]> git.ipfire.org Git - thirdparty/bash.git/blame - doc/bash.info
bash-5.0 distribution sources and documentation
[thirdparty/bash.git] / doc / bash.info
CommitLineData
d233b485 1This is bash.info, produced by makeinfo version 6.5 from
a0c0a00f
CR
2bashref.texi.
3
4This text is a brief description of the features that are present in the
d233b485 5Bash shell (version 5.0, 7 December 2018).
a0c0a00f 6
d233b485
CR
7 This is Edition 5.0, last updated 7 December 2018, of 'The GNU Bash
8Reference Manual', for 'Bash', Version 5.0.
a0c0a00f 9
d233b485 10 Copyright (C) 1988-2018 Free Software Foundation, Inc.
a0c0a00f
CR
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".
18INFO-DIR-SECTION Basics
19START-INFO-DIR-ENTRY
20* Bash: (bash). The GNU Bourne-Again SHell.
21END-INFO-DIR-ENTRY
22
23\1f
24File: bash.info, Node: Top, Next: Introduction, Prev: (dir), Up: (dir)
25
26Bash Features
27*************
28
29This text is a brief description of the features that are present in the
d233b485 30Bash shell (version 5.0, 7 December 2018). The Bash home page is
a0c0a00f
CR
31<http://www.gnu.org/software/bash/>.
32
d233b485
CR
33 This is Edition 5.0, last updated 7 December 2018, of 'The GNU Bash
34Reference Manual', for 'Bash', Version 5.0.
a0c0a00f
CR
35
36 Bash contains features that appear in other popular shells, and some
37features that only appear in Bash. Some of the shells that Bash has
38borrowed concepts from are the Bourne Shell ('sh'), the Korn Shell
39('ksh'), and the C-shell ('csh' and its successor, 'tcsh'). The
40following menu breaks the features up into categories, noting which
41features 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
44Bash. The Bash manual page should be used as the definitive reference
45on 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
70File: bash.info, Node: Introduction, Next: Definitions, Up: Top
71
721 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
81File: bash.info, Node: What is Bash?, Next: What is a shell?, Up: Introduction
82
831.1 What is Bash?
84=================
85
86Bash is the shell, or command language interpreter, for the GNU
87operating system. The name is an acronym for the 'Bourne-Again SHell',
88a pun on Stephen Bourne, the author of the direct ancestor of the
89current Unix shell 'sh', which appeared in the Seventh Edition Bell Labs
90Research version of Unix.
91
92 Bash is largely compatible with 'sh' and incorporates useful features
93from the Korn shell 'ksh' and the C shell 'csh'. It is intended to be a
94conformant implementation of the IEEE POSIX Shell and Tools portion of
95the IEEE POSIX specification (IEEE Standard 1003.1). It offers
96functional improvements over 'sh' for both interactive and programming
97use.
98
99 While the GNU operating system provides other shells, including a
100version of 'csh', Bash is the default shell. Like other GNU software,
101Bash is quite portable. It currently runs on nearly every version of
102Unix and a few other operating systems - independently-supported ports
103exist for MS-DOS, OS/2, and Windows platforms.
104
105\1f
106File: bash.info, Node: What is a shell?, Prev: What is Bash?, Up: Introduction
107
1081.2 What is a shell?
109====================
110
111At its base, a shell is simply a macro processor that executes commands.
112The term macro processor means functionality where text and symbols are
113expanded to create larger expressions.
114
115 A Unix shell is both a command interpreter and a programming
116language. As a command interpreter, the shell provides the user
117interface to the rich set of GNU utilities. The programming language
118features allow these utilities to be combined. Files containing
119commands can be created, and become commands themselves. These new
120commands have the same status as system commands in directories such as
121'/bin', allowing users or groups to establish custom environments to
122automate their common tasks.
123
124 Shells may be used interactively or non-interactively. In
125interactive mode, they accept input typed from the keyboard. When
126executing non-interactively, shells execute commands read from a file.
127
128 A shell allows execution of GNU commands, both synchronously and
129asynchronously. The shell waits for synchronous commands to complete
130before accepting more input; asynchronous commands continue to execute
131in parallel with the shell while it reads and executes additional
132commands. The "redirection" constructs permit fine-grained control of
133the input and output of those commands. Moreover, the shell allows
134control over the contents of commands' environments.
135
136 Shells also provide a small set of built-in commands ("builtins")
137implementing functionality impossible or inconvenient to obtain via
138separate utilities. For example, 'cd', 'break', 'continue', and 'exec'
139cannot be implemented outside of the shell because they directly
140manipulate the shell itself. The 'history', 'getopts', 'kill', or 'pwd'
141builtins, among others, could be implemented in separate utilities, but
142they are more convenient to use as builtin commands. All of the shell
143builtins are described in subsequent sections.
144
145 While executing commands is essential, most of the power (and
146complexity) of shells is due to their embedded programming languages.
147Like any high-level language, the shell provides variables, flow control
148constructs, quoting, and functions.
149
150 Shells offer features geared specifically for interactive use rather
151than to augment the programming language. These interactive features
152include job control, command line editing, command history and aliases.
153Each of these features is described in this manual.
154
155\1f
156File: bash.info, Node: Definitions, Next: Basic Shell Features, Prev: Introduction, Up: Top
157
1582 Definitions
159*************
160
161These 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
249File: bash.info, Node: Basic Shell Features, Next: Shell Builtin Commands, Prev: Definitions, Up: Top
250
2513 Basic Shell Features
252**********************
253
254Bash is an acronym for 'Bourne-Again SHell'. The Bourne shell is the
255traditional Unix shell originally written by Stephen Bourne. All of the
256Bourne shell builtin commands are available in Bash, The rules for
257evaluation 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':
261commands, control structures, shell functions, shell parameters, shell
262expansions, redirections, which are a way to direct input and output
263from 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
278File: bash.info, Node: Shell Syntax, Next: Shell Commands, Up: Basic Shell Features
279
2803.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
289When the shell reads input, it proceeds through a sequence of
290operations. If the input indicates the beginning of a comment, the
291shell ignores the comment symbol ('#'), and the rest of that line.
292
293 Otherwise, roughly speaking, the shell reads its input and divides
294the input into words and operators, employing the quoting rules to
295select which meanings to assign various words and characters.
296
297 The shell then parses these tokens into commands and other
298constructs, removes the special meaning of certain words or characters,
299expands others, redirects input and output as needed, executes the
300specified command, waits for the command's exit status, and makes that
301exit status available for further inspection or processing.
302
303\1f
304File: bash.info, Node: Shell Operation, Next: Quoting, Up: Shell Syntax
305
3063.1.1 Shell Operation
307---------------------
308
309The following is a brief description of the shell's operation when it
310reads 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
338File: bash.info, Node: Quoting, Next: Comments, Prev: Shell Operation, Up: Shell Syntax
339
3403.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
354Quoting is used to remove the special meaning of certain characters or
355words to the shell. Quoting can be used to disable special treatment
356for special characters, to prevent reserved words from being recognized
357as such, and to prevent parameter expansion.
358
359 Each of the shell metacharacters (*note Definitions::) has special
360meaning to the shell and must be quoted if it is to represent itself.
361When the command history expansion facilities are being used (*note
362History Interaction::), the HISTORY EXPANSION character, usually '!',
363must be quoted to prevent history expansion. *Note Bash History
364Facilities::, for more details concerning history expansion.
365
366 There are three quoting mechanisms: the ESCAPE CHARACTER, single
367quotes, and double quotes.
368
369\1f
370File: bash.info, Node: Escape Character, Next: Single Quotes, Up: Quoting
371
3723.1.2.1 Escape Character
373........................
374
375A non-quoted backslash '\' is the Bash escape character. It preserves
376the literal value of the next character that follows, with the exception
377of 'newline'. If a '\newline' pair appears, and the backslash itself is
378not quoted, the '\newline' is treated as a line continuation (that is,
379it is removed from the input stream and effectively ignored).
380
381\1f
382File: bash.info, Node: Single Quotes, Next: Double Quotes, Prev: Escape Character, Up: Quoting
383
3843.1.2.2 Single Quotes
385.....................
386
387Enclosing characters in single quotes (''') preserves the literal value
388of each character within the quotes. A single quote may not occur
389between single quotes, even when preceded by a backslash.
390
391\1f
392File: bash.info, Node: Double Quotes, Next: ANSI-C Quoting, Prev: Single Quotes, Up: Quoting
393
3943.1.2.3 Double Quotes
395.....................
396
397Enclosing characters in double quotes ('"') preserves the literal value
398of all characters within the quotes, with the exception of '$', '`',
399'\', and, when history expansion is enabled, '!'. When the shell is in
400POSIX mode (*note Bash POSIX Mode::), the '!' has no special meaning
401within double quotes, even when history expansion is enabled. The
402characters '$' and '`' retain their special meaning within double quotes
403(*note Shell Expansions::). The backslash retains its special meaning
404only when followed by one of the following characters: '$', '`', '"',
405'\', or 'newline'. Within double quotes, backslashes that are followed
406by one of these characters are removed. Backslashes preceding
407characters without a special meaning are left unmodified. A double
408quote may be quoted within double quotes by preceding it with a
409backslash. If enabled, history expansion will be performed unless an
410'!' appearing in double quotes is escaped using a backslash. The
411backslash preceding the '!' is not removed.
412
413 The special parameters '*' and '@' have special meaning when in
414double quotes (*note Shell Parameter Expansion::).
415
416\1f
417File: bash.info, Node: ANSI-C Quoting, Next: Locale Translation, Prev: Double Quotes, Up: Quoting
418
4193.1.2.4 ANSI-C Quoting
420......................
421
422Words of the form '$'STRING'' are treated specially. The word expands
423to STRING, with backslash-escaped characters replaced as specified by
424the ANSI C standard. Backslash escape sequences, if present, are
425decoded 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
d233b485 454 three octal digits)
a0c0a00f
CR
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
467The expanded result is single-quoted, as if the dollar sign had not been
468present.
469
470\1f
471File: bash.info, Node: Locale Translation, Prev: ANSI-C Quoting, Up: Quoting
472
4733.1.2.5 Locale-Specific Translation
474...................................
475
476A double-quoted string preceded by a dollar sign ('$') will cause the
477string to be translated according to the current locale. If the current
478locale is 'C' or 'POSIX', the dollar sign is ignored. If the string is
479translated and replaced, the replacement is double-quoted.
480
481 Some systems use the message catalog selected by the 'LC_MESSAGES'
482shell variable. Others create the name of the message catalog from the
483value 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.
486Still others use both variables in this fashion:
487'TEXTDOMAINDIR'/'LC_MESSAGES'/LC_MESSAGES/'TEXTDOMAIN'.mo.
488
489\1f
490File: bash.info, Node: Comments, Prev: Quoting, Up: Shell Syntax
491
4923.1.3 Comments
493--------------
494
495In a non-interactive shell, or an interactive shell in which the
496'interactive_comments' option to the 'shopt' builtin is enabled (*note
497The Shopt Builtin::), a word beginning with '#' causes that word and all
498remaining characters on that line to be ignored. An interactive shell
499without the 'interactive_comments' option enabled does not allow
500comments. The 'interactive_comments' option is on by default in
501interactive shells. *Note Interactive Shells::, for a description of
502what makes a shell interactive.
503
504\1f
505File: bash.info, Node: Shell Commands, Next: Shell Functions, Prev: Shell Syntax, Up: Basic Shell Features
506
5073.2 Shell Commands
508==================
509
510A simple shell command such as 'echo a b c' consists of the command
511itself followed by arguments, separated by spaces.
512
513 More complex shell commands are composed of simple commands arranged
514together in a variety of ways: in a pipeline in which the output of one
515command becomes the input of a second, in a loop or conditional
516construct, 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
529File: bash.info, Node: Simple Commands, Next: Pipelines, Up: Shell Commands
530
5313.2.1 Simple Commands
532---------------------
533
534A simple command is the kind of command encountered most often. It's
535just a sequence of words separated by 'blank's, terminated by one of the
536shell's control operators (*note Definitions::). The first word
537generally specifies a command to be executed, with the rest of the words
538being that command's arguments.
539
540 The return status (*note Exit Status::) of a simple command is its
541exit status as provided by the POSIX 1003.1 'waitpid' function, or 128+N
542if the command was terminated by signal N.
543
544\1f
545File: bash.info, Node: Pipelines, Next: Lists, Prev: Simple Commands, Up: Shell Commands
546
5473.2.2 Pipelines
548---------------
549
550A 'pipeline' is a sequence of one or more commands separated by one of
551the control operators '|' or '|&'.
552
553 The format for a pipeline is
554 [time [-p]] [!] COMMAND1 [ | or |& COMMAND2 ] ...
555
556The output of each command in the pipeline is connected via a pipe to
557the input of the next command. That is, each command reads the previous
558command's output. This connection is performed before any redirections
559specified by the command.
560
561 If '|&' is used, COMMAND1's standard error, in addition to its
562standard output, is connected to COMMAND2's standard input through the
563pipe; it is shorthand for '2>&1 |'. This implicit redirection of the
564standard error to the standard output is performed after any
565redirections specified by the command.
566
567 The reserved word 'time' causes timing statistics to be printed for
568the pipeline once it finishes. The statistics currently consist of
569elapsed (wall-clock) time and user and system time consumed by the
570command's execution. The '-p' option changes the output format to that
571specified by POSIX. When the shell is in POSIX mode (*note Bash POSIX
572Mode::), it does not recognize 'time' as a reserved word if the next
573token begins with a '-'. The 'TIMEFORMAT' variable may be set to a
574format string that specifies how the timing information should be
575displayed. *Note Bash Variables::, for a description of the available
576formats. The use of 'time' as a reserved word permits the timing of
577shell builtins, shell functions, and pipelines. An external 'time'
578command cannot time these easily.
579
580 When the shell is in POSIX mode (*note Bash POSIX Mode::), 'time' may
581be followed by a newline. In this case, the shell displays the total
582user and system time consumed by the shell and its children. The
583'TIMEFORMAT' variable may be used to specify the format of the time
584information.
585
586 If the pipeline is not executed asynchronously (*note Lists::), the
587shell waits for all commands in the pipeline to complete.
588
d233b485
CR
589 Each command in a pipeline is executed in its own subshell, which is
590a separate process (*note Command Execution Environment::). If the
591'lastpipe' option is enabled using the 'shopt' builtin (*note The Shopt
592Builtin::), the last element of a pipeline may be run by the shell
593process.
594
595 The exit status of a pipeline is the exit status of the last command
596in the pipeline, unless the 'pipefail' option is enabled (*note The Set
597Builtin::). If 'pipefail' is enabled, the pipeline's return status is
598the value of the last (rightmost) command to exit with a non-zero
599status, or zero if all commands exit successfully. If the reserved word
600'!' precedes the pipeline, the exit status is the logical negation of
601the exit status as described above. The shell waits for all commands in
602the pipeline to terminate before returning a value.
a0c0a00f
CR
603
604\1f
605File: bash.info, Node: Lists, Next: Compound Commands, Prev: Pipelines, Up: Shell Commands
606
6073.2.3 Lists of Commands
608-----------------------
609
610A 'list' is a sequence of one or more pipelines separated by one of the
611operators ';', '&', '&&', or '||', and optionally terminated by one of
612';', '&', or a 'newline'.
613
614 Of these list operators, '&&' and '||' have equal precedence,
615followed by ';' and '&', which have equal precedence.
616
617 A sequence of one or more newlines may appear in a 'list' to delimit
618commands, equivalent to a semicolon.
619
620 If a command is terminated by the control operator '&', the shell
621executes the command asynchronously in a subshell. This is known as
d233b485
CR
622executing the command in the BACKGROUND, and these are referred to as
623ASYNCHRONOUS commands. The shell does not wait for the command to
624finish, and the return status is 0 (true). When job control is not
625active (*note Job Control::), the standard input for asynchronous
626commands, in the absence of any explicit redirections, is redirected
627from '/dev/null'.
a0c0a00f
CR
628
629 Commands separated by a ';' are executed sequentially; the shell
630waits for each command to terminate in turn. The return status is the
631exit status of the last command executed.
632
633 AND and OR lists are sequences of one or more pipelines separated by
634the control operators '&&' and '||', respectively. AND and OR lists are
635executed with left associativity.
636
637 An AND list has the form
638 COMMAND1 && COMMAND2
639
640COMMAND2 is executed if, and only if, COMMAND1 returns an exit status of
d233b485 641zero (success).
a0c0a00f
CR
642
643 An OR list has the form
644 COMMAND1 || COMMAND2
645
646COMMAND2 is executed if, and only if, COMMAND1 returns a non-zero exit
647status.
648
649 The return status of AND and OR lists is the exit status of the last
650command executed in the list.
651
652\1f
653File: bash.info, Node: Compound Commands, Next: Coprocesses, Prev: Lists, Up: Shell Commands
654
6553.2.4 Compound Commands
656-----------------------
657
658* Menu:
659
660* Looping Constructs:: Shell commands for iterative action.
661* Conditional Constructs:: Shell commands for conditional execution.
662* Command Grouping:: Ways to group commands.
663
d233b485
CR
664Compound commands are the shell programming language constructs. Each
665construct begins with a reserved word or control operator and is
666terminated by a corresponding reserved word or operator. Any
667redirections (*note Redirections::) associated with a compound command
668apply to all commands within that compound command unless explicitly
669overridden.
a0c0a00f
CR
670
671 In most cases a list of commands in a compound command's description
672may be separated from the rest of the command by one or more newlines,
673and may be followed by a newline in place of a semicolon.
674
675 Bash provides looping constructs, conditional commands, and
676mechanisms to group commands and execute them as a unit.
677
678\1f
679File: bash.info, Node: Looping Constructs, Next: Conditional Constructs, Up: Compound Commands
680
6813.2.4.1 Looping Constructs
682..........................
683
684Bash supports the following looping constructs.
685
686 Note that wherever a ';' appears in the description of a command's
687syntax, it may be replaced with one or more newlines.
688
689'until'
690 The syntax of the 'until' command is:
691
692 until TEST-COMMANDS; do CONSEQUENT-COMMANDS; done
693
694 Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit
695 status which is not zero. The return status is the exit status of
696 the last command executed in CONSEQUENT-COMMANDS, or zero if none
697 was executed.
698
699'while'
700 The syntax of the 'while' command is:
701
702 while TEST-COMMANDS; do CONSEQUENT-COMMANDS; done
703
704 Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit
705 status of zero. The return status is the exit status of the last
706 command executed in CONSEQUENT-COMMANDS, or zero if none was
707 executed.
708
709'for'
710 The syntax of the 'for' command is:
711
712 for NAME [ [in [WORDS ...] ] ; ] do COMMANDS; done
713
d233b485
CR
714 Expand WORDS (*note Shell Expansions::), and execute COMMANDS once
715 for each member in the resultant list, with NAME bound to the
716 current member. If 'in WORDS' is not present, the 'for' command
717 executes the COMMANDS once for each positional parameter that is
718 set, as if 'in "$@"' had been specified (*note Special
719 Parameters::).
720
721 The return status is the exit status of the last command that
722 executes. If there are no items in the expansion of WORDS, no
723 commands are executed, and the return status is zero.
a0c0a00f
CR
724
725 An alternate form of the 'for' command is also supported:
726
727 for (( EXPR1 ; EXPR2 ; EXPR3 )) ; do COMMANDS ; done
728
729 First, the arithmetic expression EXPR1 is evaluated according to
730 the rules described below (*note Shell Arithmetic::). The
731 arithmetic expression EXPR2 is then evaluated repeatedly until it
732 evaluates to zero. Each time EXPR2 evaluates to a non-zero value,
733 COMMANDS are executed and the arithmetic expression EXPR3 is
734 evaluated. If any expression is omitted, it behaves as if it
735 evaluates to 1. The return value is the exit status of the last
736 command in COMMANDS that is executed, or false if any of the
737 expressions is invalid.
738
739 The 'break' and 'continue' builtins (*note Bourne Shell Builtins::)
740may be used to control loop execution.
741
742\1f
743File: bash.info, Node: Conditional Constructs, Next: Command Grouping, Prev: Looping Constructs, Up: Compound Commands
744
7453.2.4.2 Conditional Constructs
746..............................
747
748'if'
749 The syntax of the 'if' command is:
750
751 if TEST-COMMANDS; then
752 CONSEQUENT-COMMANDS;
753 [elif MORE-TEST-COMMANDS; then
754 MORE-CONSEQUENTS;]
755 [else ALTERNATE-CONSEQUENTS;]
756 fi
757
758 The TEST-COMMANDS list is executed, and if its return status is
759 zero, the CONSEQUENT-COMMANDS list is executed. If TEST-COMMANDS
760 returns a non-zero status, each 'elif' list is executed in turn,
761 and if its exit status is zero, the corresponding MORE-CONSEQUENTS
762 is executed and the command completes. If 'else
763 ALTERNATE-CONSEQUENTS' is present, and the final command in the
764 final 'if' or 'elif' clause has a non-zero exit status, then
765 ALTERNATE-CONSEQUENTS is executed. The return status is the exit
766 status of the last command executed, or zero if no condition tested
767 true.
768
769'case'
770 The syntax of the 'case' command is:
771
d233b485
CR
772 case WORD in
773 [ [(] PATTERN [| PATTERN]...) COMMAND-LIST ;;]...
774 esac
a0c0a00f
CR
775
776 'case' will selectively execute the COMMAND-LIST corresponding to
d233b485
CR
777 the first PATTERN that matches WORD. The match is performed
778 according to the rules described below in *note Pattern Matching::.
779 If the 'nocasematch' shell option (see the description of 'shopt'
780 in *note The Shopt Builtin::) is enabled, the match is performed
781 without regard to the case of alphabetic characters. The '|' is
782 used to separate multiple patterns, and the ')' operator terminates
783 a pattern list. A list of patterns and an associated command-list
784 is known as a CLAUSE.
a0c0a00f
CR
785
786 Each clause must be terminated with ';;', ';&', or ';;&'. The WORD
787 undergoes tilde expansion, parameter expansion, command
d233b485
CR
788 substitution, arithmetic expansion, and quote removal (*note Shell
789 Parameter Expansion::) before matching is attempted. Each PATTERN
790 undergoes tilde expansion, parameter expansion, command
791 substitution, and arithmetic expansion.
a0c0a00f
CR
792
793 There may be an arbitrary number of 'case' clauses, each terminated
794 by a ';;', ';&', or ';;&'. The first pattern that matches
795 determines the command-list that is executed. It's a common idiom
796 to use '*' as the final pattern to define the default case, since
797 that pattern will always match.
798
799 Here is an example using 'case' in a script that could be used to
800 describe one interesting feature of an animal:
801
802 echo -n "Enter the name of an animal: "
803 read ANIMAL
804 echo -n "The $ANIMAL has "
805 case $ANIMAL in
806 horse | dog | cat) echo -n "four";;
807 man | kangaroo ) echo -n "two";;
808 *) echo -n "an unknown number of";;
809 esac
810 echo " legs."
811
812
813 If the ';;' operator is used, no subsequent matches are attempted
814 after the first pattern match. Using ';&' in place of ';;' causes
815 execution to continue with the COMMAND-LIST associated with the
816 next clause, if any. Using ';;&' in place of ';;' causes the shell
817 to test the patterns in the next clause, if any, and execute any
818 associated COMMAND-LIST on a successful match.
819
820 The return status is zero if no PATTERN is matched. Otherwise, the
821 return status is the exit status of the COMMAND-LIST executed.
822
823'select'
824
825 The 'select' construct allows the easy generation of menus. It has
826 almost the same syntax as the 'for' command:
827
828 select NAME [in WORDS ...]; do COMMANDS; done
829
830 The list of words following 'in' is expanded, generating a list of
831 items. The set of expanded words is printed on the standard error
832 output stream, each preceded by a number. If the 'in WORDS' is
833 omitted, the positional parameters are printed, as if 'in "$@"' had
834 been specified. The 'PS3' prompt is then displayed and a line is
835 read from the standard input. If the line consists of a number
836 corresponding to one of the displayed words, then the value of NAME
837 is set to that word. If the line is empty, the words and prompt
838 are displayed again. If 'EOF' is read, the 'select' command
839 completes. Any other value read causes NAME to be set to null.
840 The line read is saved in the variable 'REPLY'.
841
842 The COMMANDS are executed after each selection until a 'break'
843 command is executed, at which point the 'select' command completes.
844
845 Here is an example that allows the user to pick a filename from the
846 current directory, and displays the name and index of the file
847 selected.
848
849 select fname in *;
850 do
851 echo you picked $fname \($REPLY\)
852 break;
853 done
854
855'((...))'
856 (( EXPRESSION ))
857
858 The arithmetic EXPRESSION is evaluated according to the rules
859 described below (*note Shell Arithmetic::). If the value of the
860 expression is non-zero, the return status is 0; otherwise the
861 return status is 1. This is exactly equivalent to
862 let "EXPRESSION"
863 *Note Bash Builtins::, for a full description of the 'let' builtin.
864
865'[[...]]'
866 [[ EXPRESSION ]]
867
868 Return a status of 0 or 1 depending on the evaluation of the
869 conditional expression EXPRESSION. Expressions are composed of the
870 primaries described below in *note Bash Conditional Expressions::.
871 Word splitting and filename expansion are not performed on the
872 words between the '[[' and ']]'; tilde expansion, parameter and
873 variable expansion, arithmetic expansion, command substitution,
874 process substitution, and quote removal are performed. Conditional
875 operators such as '-f' must be unquoted to be recognized as
876 primaries.
877
878 When used with '[[', the '<' and '>' operators sort
879 lexicographically using the current locale.
880
881 When the '==' and '!=' operators are used, the string to the right
882 of the operator is considered a pattern and matched according to
883 the rules described below in *note Pattern Matching::, as if the
884 'extglob' shell option were enabled. The '=' operator is identical
885 to '=='. If the 'nocasematch' shell option (see the description of
886 'shopt' in *note The Shopt Builtin::) is enabled, the match is
887 performed without regard to the case of alphabetic characters. The
888 return value is 0 if the string matches ('==') or does not match
d233b485
CR
889 ('!=') the pattern, and 1 otherwise. Any part of the pattern may
890 be quoted to force the quoted portion to be matched as a string.
a0c0a00f
CR
891
892 An additional binary operator, '=~', is available, with the same
893 precedence as '==' and '!='. When it is used, the string to the
d233b485
CR
894 right of the operator is considered a POSIX extended regular
895 expression and matched accordingly (as in regex3)). The return
896 value is 0 if the string matches the pattern, and 1 otherwise. If
897 the regular expression is syntactically incorrect, the conditional
898 expression's return value is 2. If the 'nocasematch' shell option
899 (see the description of 'shopt' in *note The Shopt Builtin::) is
900 enabled, the match is performed without regard to the case of
901 alphabetic characters. Any part of the pattern may be quoted to
902 force the quoted portion to be matched as a string. Bracket
903 expressions in regular expressions must be treated carefully, since
904 normal quoting characters lose their meanings between brackets. If
905 the pattern is stored in a shell variable, quoting the variable
906 expansion forces the entire pattern to be matched as a string.
907 Substrings matched by parenthesized subexpressions within the
908 regular expression are saved in the array variable 'BASH_REMATCH'.
909 The element of 'BASH_REMATCH' with index 0 is the portion of the
910 string matching the entire regular expression. The element of
911 'BASH_REMATCH' with index N is the portion of the string matching
912 the Nth parenthesized subexpression.
a0c0a00f
CR
913
914 For example, the following will match a line (stored in the shell
915 variable LINE) if there is a sequence of characters in the value
916 consisting of any number, including zero, of space characters, zero
917 or one instances of 'a', then a 'b':
d233b485 918 [[ $line =~ [[:space:]]*?(a)b ]]
a0c0a00f
CR
919
920 That means values like 'aab' and ' aaaaaab' will match, as will a
921 line containing a 'b' anywhere in its value.
922
923 Storing the regular expression in a shell variable is often a
924 useful way to avoid problems with quoting characters that are
925 special to the shell. It is sometimes difficult to specify a
926 regular expression literally without using quotes, or to keep track
927 of the quoting used by regular expressions while paying attention
928 to the shell's quote removal. Using a shell variable to store the
929 pattern decreases these problems. For example, the following is
930 equivalent to the above:
d233b485 931 pattern='[[:space:]]*?(a)b'
a0c0a00f
CR
932 [[ $line =~ $pattern ]]
933
934 If you want to match a character that's special to the regular
935 expression grammar, it has to be quoted to remove its special
936 meaning. This means that in the pattern 'xxx.txt', the '.' matches
937 any character in the string (its usual regular expression meaning),
938 but in the pattern '"xxx.txt"' it can only match a literal '.'.
939 Shell programmers should take special care with backslashes, since
940 backslashes are used both by the shell and regular expressions to
941 remove the special meaning from the following character. The
942 following two sets of commands are _not_ equivalent:
943 pattern='\.'
944
945 [[ . =~ $pattern ]]
946 [[ . =~ \. ]]
947
948 [[ . =~ "$pattern" ]]
949 [[ . =~ '\.' ]]
950
951 The first two matches will succeed, but the second two will not,
952 because in the second two the backslash will be part of the pattern
953 to be matched. In the first two examples, the backslash removes
954 the special meaning from '.', so the literal '.' matches. If the
955 string in the first examples were anything other than '.', say 'a',
956 the pattern would not match, because the quoted '.' in the pattern
957 loses its special meaning of matching any single character.
958
959 Expressions may be combined using the following operators, listed
960 in decreasing order of precedence:
961
962 '( EXPRESSION )'
963 Returns the value of EXPRESSION. This may be used to override
964 the normal precedence of operators.
965
966 '! EXPRESSION'
967 True if EXPRESSION is false.
968
969 'EXPRESSION1 && EXPRESSION2'
970 True if both EXPRESSION1 and EXPRESSION2 are true.
971
972 'EXPRESSION1 || EXPRESSION2'
973 True if either EXPRESSION1 or EXPRESSION2 is true.
974
975 The '&&' and '||' operators do not evaluate EXPRESSION2 if the
976 value of EXPRESSION1 is sufficient to determine the return value of
977 the entire conditional expression.
978
979\1f
980File: bash.info, Node: Command Grouping, Prev: Conditional Constructs, Up: Compound Commands
981
9823.2.4.3 Grouping Commands
983.........................
984
985Bash provides two ways to group a list of commands to be executed as a
986unit. When commands are grouped, redirections may be applied to the
987entire command list. For example, the output of all the commands in the
988list may be redirected to a single stream.
989
990'()'
991 ( LIST )
992
993 Placing a list of commands between parentheses causes a subshell
994 environment to be created (*note Command Execution Environment::),
995 and each of the commands in LIST to be executed in that subshell.
996 Since the LIST is executed in a subshell, variable assignments do
997 not remain in effect after the subshell completes.
998
999'{}'
1000 { LIST; }
1001
1002 Placing a list of commands between curly braces causes the list to
1003 be executed in the current shell context. No subshell is created.
1004 The semicolon (or newline) following LIST is required.
1005
1006 In addition to the creation of a subshell, there is a subtle
1007difference between these two constructs due to historical reasons. The
1008braces are 'reserved words', so they must be separated from the LIST by
1009'blank's or other shell metacharacters. The parentheses are
1010'operators', and are recognized as separate tokens by the shell even if
1011they are not separated from the LIST by whitespace.
1012
1013 The exit status of both of these constructs is the exit status of
1014LIST.
1015
1016\1f
1017File: bash.info, Node: Coprocesses, Next: GNU Parallel, Prev: Compound Commands, Up: Shell Commands
1018
10193.2.5 Coprocesses
1020-----------------
1021
1022A 'coprocess' is a shell command preceded by the 'coproc' reserved word.
1023A coprocess is executed asynchronously in a subshell, as if the command
1024had been terminated with the '&' control operator, with a two-way pipe
1025established between the executing shell and the coprocess.
1026
1027 The format for a coprocess is:
1028 coproc [NAME] COMMAND [REDIRECTIONS]
1029
1030This creates a coprocess named NAME. If NAME is not supplied, the
1031default name is COPROC. NAME must not be supplied if COMMAND is a
1032simple command (*note Simple Commands::); otherwise, it is interpreted
1033as the first word of the simple command.
1034
1035 When the coprocess is executed, the shell creates an array variable
1036(*note Arrays::) named 'NAME' in the context of the executing shell.
1037The standard output of COMMAND is connected via a pipe to a file
1038descriptor in the executing shell, and that file descriptor is assigned
1039to 'NAME'[0]. The standard input of COMMAND is connected via a pipe to
1040a file descriptor in the executing shell, and that file descriptor is
1041assigned to 'NAME'[1]. This pipe is established before any redirections
1042specified by the command (*note Redirections::). The file descriptors
1043can be utilized as arguments to shell commands and redirections using
d233b485
CR
1044standard word expansions. Other than those created to execute command
1045and process substitutions, the file descriptors are not available in
a0c0a00f
CR
1046subshells.
1047
1048 The process ID of the shell spawned to execute the coprocess is
1049available as the value of the variable 'NAME'_PID. The 'wait' builtin
1050command may be used to wait for the coprocess to terminate.
1051
1052 Since the coprocess is created as an asynchronous command, the
1053'coproc' command always returns success. The return status of a
1054coprocess is the exit status of COMMAND.
1055
1056\1f
1057File: bash.info, Node: GNU Parallel, Prev: Coprocesses, Up: Shell Commands
1058
10593.2.6 GNU Parallel
1060------------------
1061
1062There are ways to run commands in parallel that are not built into Bash.
1063GNU Parallel is a tool to do just that.
1064
1065 GNU Parallel, as its name suggests, can be used to build and run
1066commands in parallel. You may run the same command with different
1067arguments, whether they are filenames, usernames, hostnames, or lines
1068read from files. GNU Parallel provides shorthand references to many of
1069the most common operations (input lines, various portions of the input
1070line, different ways to specify the input source, and so on). Parallel
1071can replace 'xargs' or feed commands from its input sources to several
1072different instances of Bash.
1073
1074 For a complete description, refer to the GNU Parallel documentation.
1075A few examples should provide a brief introduction to its use.
1076
1077 For example, it is easy to replace 'xargs' to gzip all html files in
1078the current directory and its subdirectories:
1079 find . -type f -name '*.html' -print | parallel gzip
1080If you need to protect special characters such as newlines in file
1081names, use find's '-print0' option and parallel's '-0' option.
1082
1083 You can use Parallel to move files from the current directory when
1084the number of files is too large to process with one 'mv' invocation:
1085 ls | parallel mv {} destdir
1086
1087 As you can see, the {} is replaced with each line read from standard
1088input. While using 'ls' will work in most instances, it is not
1089sufficient to deal with all filenames. If you need to accommodate
1090special characters in filenames, you can use
1091
1092 find . -depth 1 \! -name '.*' -print0 | parallel -0 mv {} destdir
1093
1094as alluded to above.
1095
1096 This will run as many 'mv' commands as there are files in the current
1097directory. You can emulate a parallel 'xargs' by adding the '-X'
1098option:
1099 find . -depth 1 \! -name '.*' -print0 | parallel -0 -X mv {} destdir
1100
1101 GNU Parallel can replace certain common idioms that operate on lines
1102read from a file (in this case, filenames listed one per line):
1103 while IFS= read -r x; do
1104 do-something1 "$x" "config-$x"
1105 do-something2 < "$x"
1106 done < file | process-output
1107
1108with a more compact syntax reminiscent of lambdas:
d233b485
CR
1109 cat list | parallel "do-something1 {} config-{} ; do-something2 < {}" |
1110 process-output
a0c0a00f
CR
1111
1112 Parallel provides a built-in mechanism to remove filename extensions,
1113which lends itself to batch file transformations or renaming:
1114 ls *.gz | parallel -j+0 "zcat {} | bzip2 >{.}.bz2 && rm {}"
1115This will recompress all files in the current directory with names
1116ending in .gz using bzip2, running one job per CPU (-j+0) in parallel.
1117(We use 'ls' for brevity here; using 'find' as above is more robust in
1118the face of filenames containing unexpected characters.) Parallel can
1119take arguments from the command line; the above can also be written as
1120
1121 parallel "zcat {} | bzip2 >{.}.bz2 && rm {}" ::: *.gz
1122
1123 If a command generates output, you may want to preserve the input
1124order in the output. For instance, the following command
d233b485
CR
1125 {
1126 echo foss.org.my ;
1127 echo debian.org ;
1128 echo freenetproject.org ;
1129 } | parallel traceroute
a0c0a00f
CR
1130will display as output the traceroute invocation that finishes first.
1131Adding the '-k' option
d233b485
CR
1132 {
1133 echo foss.org.my ;
1134 echo debian.org ;
1135 echo freenetproject.org ;
1136 } | parallel -k traceroute
a0c0a00f
CR
1137will ensure that the output of 'traceroute foss.org.my' is displayed
1138first.
1139
1140 Finally, Parallel can be used to run a sequence of shell commands in
1141parallel, similar to 'cat file | bash'. It is not uncommon to take a
1142list of filenames, create a series of shell commands to operate on them,
d233b485 1143and feed that list of commands to a shell. Parallel can speed this up.
a0c0a00f
CR
1144Assuming that 'file' contains a list of shell commands, one per line,
1145
1146 parallel -j 10 < file
1147
1148will evaluate the commands using the shell (since no explicit command is
1149supplied as an argument), in blocks of ten shell jobs at a time.
1150
1151\1f
1152File: bash.info, Node: Shell Functions, Next: Shell Parameters, Prev: Shell Commands, Up: Basic Shell Features
1153
11543.3 Shell Functions
1155===================
1156
1157Shell functions are a way to group commands for later execution using a
1158single name for the group. They are executed just like a "regular"
1159command. When the name of a shell function is used as a simple command
1160name, the list of commands associated with that function name is
1161executed. Shell functions are executed in the current shell context; no
1162new process is created to interpret them.
1163
1164 Functions are declared using this syntax:
1165 NAME () COMPOUND-COMMAND [ REDIRECTIONS ]
1166
1167 or
1168
1169 function NAME [()] COMPOUND-COMMAND [ REDIRECTIONS ]
1170
1171 This defines a shell function named NAME. The reserved word
1172'function' is optional. If the 'function' reserved word is supplied,
1173the parentheses are optional. The BODY of the function is the compound
1174command COMPOUND-COMMAND (*note Compound Commands::). That command is
1175usually a LIST enclosed between { and }, but may be any compound command
1176listed above, with one exception: If the 'function' reserved word is
1177used, but the parentheses are not supplied, the braces are required.
1178COMPOUND-COMMAND is executed whenever NAME is specified as the name of a
1179command. When the shell is in POSIX mode (*note Bash POSIX Mode::),
1180NAME may not be the same as one of the special builtins (*note Special
1181Builtins::). Any redirections (*note Redirections::) associated with
1182the shell function are performed when the function is executed.
1183
1184 A function definition may be deleted using the '-f' option to the
1185'unset' builtin (*note Bourne Shell Builtins::).
1186
1187 The exit status of a function definition is zero unless a syntax
1188error occurs or a readonly function with the same name already exists.
1189When executed, the exit status of a function is the exit status of the
1190last command executed in the body.
1191
1192 Note that for historical reasons, in the most common usage the curly
1193braces that surround the body of the function must be separated from the
1194body by 'blank's or newlines. This is because the braces are reserved
1195words and are only recognized as such when they are separated from the
1196command list by whitespace or another shell metacharacter. Also, when
1197using the braces, the LIST must be terminated by a semicolon, a '&', or
1198a newline.
1199
1200 When a function is executed, the arguments to the function become the
1201positional parameters during its execution (*note Positional
1202Parameters::). The special parameter '#' that expands to the number of
1203positional parameters is updated to reflect the change. Special
1204parameter '0' is unchanged. The first element of the 'FUNCNAME'
1205variable is set to the name of the function while the function is
1206executing.
1207
1208 All other aspects of the shell execution environment are identical
1209between a function and its caller with these exceptions: the 'DEBUG' and
1210'RETURN' traps are not inherited unless the function has been given the
1211'trace' attribute using the 'declare' builtin or the '-o functrace'
1212option has been enabled with the 'set' builtin, (in which case all
1213functions inherit the 'DEBUG' and 'RETURN' traps), and the 'ERR' trap is
1214not inherited unless the '-o errtrace' shell option has been enabled.
1215*Note Bourne Shell Builtins::, for the description of the 'trap'
1216builtin.
1217
1218 The 'FUNCNEST' variable, if set to a numeric value greater than 0,
1219defines a maximum function nesting level. Function invocations that
1220exceed the limit cause the entire command to abort.
1221
1222 If the builtin command 'return' is executed in a function, the
1223function completes and execution resumes with the next command after the
1224function call. Any command associated with the 'RETURN' trap is
1225executed before execution resumes. When a function completes, the
1226values of the positional parameters and the special parameter '#' are
1227restored to the values they had prior to the function's execution. If a
1228numeric argument is given to 'return', that is the function's return
1229status; otherwise the function's return status is the exit status of the
1230last command executed before the 'return'.
1231
1232 Variables local to the function may be declared with the 'local'
1233builtin. These variables are visible only to the function and the
d233b485
CR
1234commands it invokes. This is particularly important when a shell
1235function calls other functions.
1236
1237 Local variables "shadow" variables with the same name declared at
1238previous scopes. For instance, a local variable declared in a function
1239hides a global variable of the same name: references and assignments
1240refer to the local variable, leaving the global variable unmodified.
1241When the function returns, the global variable is once again visible.
1242
1243 The shell uses DYNAMIC SCOPING to control a variable's visibility
1244within functions. With dynamic scoping, visible variables and their
1245values are a result of the sequence of function calls that caused
1246execution to reach the current function. The value of a variable that a
1247function sees depends on its value within its caller, if any, whether
1248that caller is the "global" scope or another shell function. This is
1249also the value that a local variable declaration "shadows", and the
1250value that is restored when the function returns.
1251
1252 For example, if a variable VAR is declared as local in function
1253FUNC1, and FUNC1 calls another function FUNC2, references to VAR made
1254from within FUNC2 will resolve to the local variable VAR from FUNC1,
1255shadowing any global variable named VAR.
1256
1257 The following script demonstrates this behavior. When executed, the
1258script displays
1259
1260 In func2, var = func1 local
1261
1262 func1()
1263 {
1264 local var='func1 local'
1265 func2
1266 }
1267
1268 func2()
1269 {
1270 echo "In func2, var = $var"
1271 }
1272
1273 var=global
1274 func1
1275
1276 The 'unset' builtin also acts using the same dynamic scope: if a
1277variable is local to the current scope, 'unset' will unset it; otherwise
1278the unset will refer to the variable found in any calling scope as
1279described above. If a variable at the current local scope is unset, it
1280will remain so until it is reset in that scope or until the function
1281returns. Once the function returns, any instance of the variable at a
1282previous scope will become visible. If the unset acts on a variable at
1283a previous scope, any instance of a variable with that name that had
1284been shadowed will become visible.
a0c0a00f
CR
1285
1286 Function names and definitions may be listed with the '-f' option to
1287the 'declare' ('typeset') builtin command (*note Bash Builtins::). The
1288'-F' option to 'declare' or 'typeset' will list the function names only
1289(and optionally the source file and line number, if the 'extdebug' shell
1290option is enabled). Functions may be exported so that subshells
1291automatically have them defined with the '-f' option to the 'export'
d233b485 1292builtin (*note Bourne Shell Builtins::).
a0c0a00f
CR
1293
1294 Functions may be recursive. The 'FUNCNEST' variable may be used to
1295limit the depth of the function call stack and restrict the number of
1296function invocations. By default, no limit is placed on the number of
1297recursive calls.
1298
1299\1f
1300File: bash.info, Node: Shell Parameters, Next: Shell Expansions, Prev: Shell Functions, Up: Basic Shell Features
1301
13023.4 Shell Parameters
1303====================
1304
1305* Menu:
1306
1307* Positional Parameters:: The shell's command-line arguments.
1308* Special Parameters:: Parameters denoted by special characters.
1309
1310A PARAMETER is an entity that stores values. It can be a 'name', a
1311number, or one of the special characters listed below. A VARIABLE is a
1312parameter denoted by a 'name'. A variable has a VALUE and zero or more
1313ATTRIBUTES. Attributes are assigned using the 'declare' builtin command
1314(see the description of the 'declare' builtin in *note Bash Builtins::).
1315
1316 A parameter is set if it has been assigned a value. The null string
1317is a valid value. Once a variable is set, it may be unset only by using
1318the 'unset' builtin command.
1319
1320 A variable may be assigned to by a statement of the form
1321 NAME=[VALUE]
1322If VALUE is not given, the variable is assigned the null string. All
1323VALUEs undergo tilde expansion, parameter and variable expansion,
1324command substitution, arithmetic expansion, and quote removal (detailed
1325below). If the variable has its 'integer' attribute set, then VALUE is
1326evaluated as an arithmetic expression even if the '$((...))' expansion
1327is not used (*note Arithmetic Expansion::). Word splitting is not
1328performed, with the exception of '"$@"' as explained below. Filename
1329expansion is not performed. Assignment statements may also appear as
1330arguments to the 'alias', 'declare', 'typeset', 'export', 'readonly',
1331and 'local' builtin commands (DECLARATION commands). When in POSIX mode
1332(*note Bash POSIX Mode::), these builtins may appear in a command after
1333one or more instances of the 'command' builtin and retain these
1334assignment statement properties.
1335
1336 In the context where an assignment statement is assigning a value to
1337a shell variable or array index (*note Arrays::), the '+=' operator can
1338be used to append to or add to the variable's previous value. This
1339includes arguments to builtin commands such as 'declare' that accept
1340assignment statements (DECLARATION commands). When '+=' is applied to a
1341variable for which the INTEGER attribute has been set, VALUE is
1342evaluated as an arithmetic expression and added to the variable's
1343current value, which is also evaluated. When '+=' is applied to an
1344array variable using compound assignment (*note Arrays::), the
1345variable's value is not unset (as it is when using '='), and new values
1346are appended to the array beginning at one greater than the array's
1347maximum index (for indexed arrays), or added as additional key-value
1348pairs in an associative array. When applied to a string-valued
1349variable, VALUE is expanded and appended to the variable's value.
1350
1351 A variable can be assigned the NAMEREF attribute using the '-n'
1352option to the 'declare' or 'local' builtin commands (*note Bash
1353Builtins::) to create a NAMEREF, or a reference to another variable.
1354This allows variables to be manipulated indirectly. Whenever the
1355nameref variable is referenced, assigned to, unset, or has its
1356attributes modified (other than using or changing the nameref attribute
1357itself), the operation is actually performed on the variable specified
1358by the nameref variable's value. A nameref is commonly used within
1359shell functions to refer to a variable whose name is passed as an
1360argument to the function. For instance, if a variable name is passed to
1361a shell function as its first argument, running
1362 declare -n ref=$1
1363inside the function creates a nameref variable REF whose value is the
1364variable name passed as the first argument. References and assignments
1365to REF, and changes to its attributes, are treated as references,
1366assignments, and attribute modifications to the variable whose name was
1367passed as '$1'.
1368
1369 If the control variable in a 'for' loop has the nameref attribute,
1370the list of words can be a list of shell variables, and a name reference
1371will be established for each word in the list, in turn, when the loop is
1372executed. Array variables cannot be given the nameref attribute.
1373However, nameref variables can reference array variables and subscripted
1374array variables. Namerefs can be unset using the '-n' option to the
1375'unset' builtin (*note Bourne Shell Builtins::). Otherwise, if 'unset'
1376is executed with the name of a nameref variable as an argument, the
1377variable referenced by the nameref variable will be unset.
1378
1379\1f
1380File: bash.info, Node: Positional Parameters, Next: Special Parameters, Up: Shell Parameters
1381
13823.4.1 Positional Parameters
1383---------------------------
1384
1385A POSITIONAL PARAMETER is a parameter denoted by one or more digits,
1386other than the single digit '0'. Positional parameters are assigned
1387from the shell's arguments when it is invoked, and may be reassigned
1388using the 'set' builtin command. Positional parameter 'N' may be
1389referenced as '${N}', or as '$N' when 'N' consists of a single digit.
1390Positional parameters may not be assigned to with assignment statements.
1391The 'set' and 'shift' builtins are used to set and unset them (*note
1392Shell Builtin Commands::). The positional parameters are temporarily
1393replaced when a shell function is executed (*note Shell Functions::).
1394
1395 When a positional parameter consisting of more than a single digit is
1396expanded, it must be enclosed in braces.
1397
1398\1f
1399File: bash.info, Node: Special Parameters, Prev: Positional Parameters, Up: Shell Parameters
1400
14013.4.2 Special Parameters
1402------------------------
1403
1404The shell treats several parameters specially. These parameters may
1405only be referenced; assignment to them is not allowed.
1406
1407'*'
1408 ($*) Expands to the positional parameters, starting from one. When
1409 the expansion is not within double quotes, each positional
1410 parameter expands to a separate word. In contexts where it is
1411 performed, those words are subject to further word splitting and
1412 pathname expansion. When the expansion occurs within double
1413 quotes, it expands to a single word with the value of each
1414 parameter separated by the first character of the 'IFS' special
1415 variable. That is, '"$*"' is equivalent to '"$1C$2C..."', where C
1416 is the first character of the value of the 'IFS' variable. If
1417 'IFS' is unset, the parameters are separated by spaces. If 'IFS'
1418 is null, the parameters are joined without intervening separators.
1419
1420'@'
d233b485
CR
1421 ($@) Expands to the positional parameters, starting from one. In
1422 contexts where word splitting is performed, this expands each
1423 positional parameter to a separate word; if not within double
1424 quotes, these words are subject to word splitting. In contexts
1425 where word splitting is not performed, this expands to a single
1426 word with each positional parameter separated by a space. When the
1427 expansion occurs within double quotes, and word splitting is
1428 performed, each parameter expands to a separate word. That is,
1429 '"$@"' is equivalent to '"$1" "$2" ...'. If the double-quoted
1430 expansion occurs within a word, the expansion of the first
1431 parameter is joined with the beginning part of the original word,
1432 and the expansion of the last parameter is joined with the last
1433 part of the original word. When there are no positional
1434 parameters, '"$@"' and '$@' expand to nothing (i.e., they are
1435 removed).
a0c0a00f
CR
1436
1437'#'
1438 ($#) Expands to the number of positional parameters in decimal.
1439
1440'?'
1441 ($?) Expands to the exit status of the most recently executed
1442 foreground pipeline.
1443
1444'-'
1445 ($-, a hyphen.) Expands to the current option flags as specified
1446 upon invocation, by the 'set' builtin command, or those set by the
1447 shell itself (such as the '-i' option).
1448
1449'$'
1450 ($$) Expands to the process ID of the shell. In a '()' subshell,
1451 it expands to the process ID of the invoking shell, not the
1452 subshell.
1453
1454'!'
1455 ($!) Expands to the process ID of the job most recently placed
1456 into the background, whether executed as an asynchronous command or
1457 using the 'bg' builtin (*note Job Control Builtins::).
1458
1459'0'
1460 ($0) Expands to the name of the shell or shell script. This is set
1461 at shell initialization. If Bash is invoked with a file of
1462 commands (*note Shell Scripts::), '$0' is set to the name of that
1463 file. If Bash is started with the '-c' option (*note Invoking
1464 Bash::), then '$0' is set to the first argument after the string to
1465 be executed, if one is present. Otherwise, it is set to the
1466 filename used to invoke Bash, as given by argument zero.
1467
1468'_'
1469 ($_, an underscore.) At shell startup, set to the absolute
1470 pathname used to invoke the shell or shell script being executed as
1471 passed in the environment or argument list. Subsequently, expands
d233b485
CR
1472 to the last argument to the previous simple command executed in the
1473 foreground, after expansion. Also set to the full pathname used to
1474 invoke each command executed and placed in the environment exported
1475 to that command. When checking mail, this parameter holds the name
1476 of the mail file.
a0c0a00f
CR
1477
1478\1f
1479File: bash.info, Node: Shell Expansions, Next: Redirections, Prev: Shell Parameters, Up: Basic Shell Features
1480
14813.5 Shell Expansions
1482====================
1483
1484Expansion is performed on the command line after it has been split into
1485'token's. There are seven kinds of expansion performed:
1486
1487 * brace expansion
1488 * tilde expansion
1489 * parameter and variable expansion
1490 * command substitution
1491 * arithmetic expansion
1492 * word splitting
1493 * filename expansion
1494
1495* Menu:
1496
1497* Brace Expansion:: Expansion of expressions within braces.
1498* Tilde Expansion:: Expansion of the ~ character.
1499* Shell Parameter Expansion:: How Bash expands variables to their values.
1500* Command Substitution:: Using the output of a command as an argument.
1501* Arithmetic Expansion:: How to use arithmetic in shell expansions.
1502* Process Substitution:: A way to write and read to and from a
1503 command.
1504* Word Splitting:: How the results of expansion are split into separate
1505 arguments.
1506* Filename Expansion:: A shorthand for specifying filenames matching patterns.
1507* Quote Removal:: How and when quote characters are removed from
1508 words.
1509
1510 The order of expansions is: brace expansion; tilde expansion,
1511parameter and variable expansion, arithmetic expansion, and command
1512substitution (done in a left-to-right fashion); word splitting; and
1513filename expansion.
1514
1515 On systems that can support it, there is an additional expansion
1516available: PROCESS SUBSTITUTION. This is performed at the same time as
1517tilde, parameter, variable, and arithmetic expansion and command
1518substitution.
1519
1520 After these expansions are performed, quote characters present in the
1521original word are removed unless they have been quoted themselves (QUOTE
1522REMOVAL).
1523
1524 Only brace expansion, word splitting, and filename expansion can
d233b485 1525increase the number of words of the expansion; other expansions expand a
a0c0a00f 1526single word to a single word. The only exceptions to this are the
d233b485
CR
1527expansions of '"$@"' and '$*' (*note Special Parameters::), and
1528'"${NAME[@]}"' and '${NAME[*]}' (*note Arrays::).
a0c0a00f
CR
1529
1530 After all expansions, 'quote removal' (*note Quote Removal::) is
1531performed.
1532
1533\1f
1534File: bash.info, Node: Brace Expansion, Next: Tilde Expansion, Up: Shell Expansions
1535
15363.5.1 Brace Expansion
1537---------------------
1538
1539Brace expansion is a mechanism by which arbitrary strings may be
1540generated. This mechanism is similar to FILENAME EXPANSION (*note
1541Filename Expansion::), but the filenames generated need not exist.
1542Patterns to be brace expanded take the form of an optional PREAMBLE,
1543followed by either a series of comma-separated strings or a sequence
1544expression between a pair of braces, followed by an optional POSTSCRIPT.
1545The preamble is prefixed to each string contained within the braces, and
1546the postscript is then appended to each resulting string, expanding left
1547to right.
1548
1549 Brace expansions may be nested. The results of each expanded string
1550are not sorted; left to right order is preserved. For example,
1551 bash$ echo a{d,c,b}e
1552 ade ace abe
1553
1554 A sequence expression takes the form '{X..Y[..INCR]}', where X and Y
1555are either integers or single characters, and INCR, an optional
1556increment, is an integer. When integers are supplied, the expression
1557expands to each number between X and Y, inclusive. Supplied integers
1558may be prefixed with '0' to force each term to have the same width.
1559When either X or Y begins with a zero, the shell attempts to force all
1560generated terms to contain the same number of digits, zero-padding where
1561necessary. When characters are supplied, the expression expands to each
1562character lexicographically between X and Y, inclusive, using the
1563default C locale. Note that both X and Y must be of the same type.
1564When the increment is supplied, it is used as the difference between
1565each term. The default increment is 1 or -1 as appropriate.
1566
1567 Brace expansion is performed before any other expansions, and any
1568characters special to other expansions are preserved in the result. It
1569is strictly textual. Bash does not apply any syntactic interpretation
d233b485 1570to the context of the expansion or the text between the braces.
a0c0a00f
CR
1571
1572 A correctly-formed brace expansion must contain unquoted opening and
1573closing braces, and at least one unquoted comma or a valid sequence
1574expression. Any incorrectly formed brace expansion is left unchanged.
1575
1576 A { or ',' may be quoted with a backslash to prevent its being
1577considered part of a brace expression. To avoid conflicts with
1578parameter expansion, the string '${' is not considered eligible for
d233b485 1579brace expansion, and inhibits brace expansion until the closing '}'..
a0c0a00f
CR
1580
1581 This construct is typically used as shorthand when the common prefix
1582of the strings to be generated is longer than in the above example:
1583 mkdir /usr/local/src/bash/{old,new,dist,bugs}
1584 or
1585 chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
1586
1587\1f
1588File: bash.info, Node: Tilde Expansion, Next: Shell Parameter Expansion, Prev: Brace Expansion, Up: Shell Expansions
1589
15903.5.2 Tilde Expansion
1591---------------------
1592
1593If a word begins with an unquoted tilde character ('~'), all of the
1594characters up to the first unquoted slash (or all characters, if there
1595is no unquoted slash) are considered a TILDE-PREFIX. If none of the
1596characters in the tilde-prefix are quoted, the characters in the
1597tilde-prefix following the tilde are treated as a possible LOGIN NAME.
1598If this login name is the null string, the tilde is replaced with the
1599value of the 'HOME' shell variable. If 'HOME' is unset, the home
1600directory of the user executing the shell is substituted instead.
1601Otherwise, the tilde-prefix is replaced with the home directory
1602associated with the specified login name.
1603
1604 If the tilde-prefix is '~+', the value of the shell variable 'PWD'
1605replaces the tilde-prefix. If the tilde-prefix is '~-', the value of
1606the shell variable 'OLDPWD', if it is set, is substituted.
1607
1608 If the characters following the tilde in the tilde-prefix consist of
1609a number N, optionally prefixed by a '+' or a '-', the tilde-prefix is
1610replaced with the corresponding element from the directory stack, as it
1611would be displayed by the 'dirs' builtin invoked with the characters
1612following tilde in the tilde-prefix as an argument (*note The Directory
1613Stack::). If the tilde-prefix, sans the tilde, consists of a number
1614without a leading '+' or '-', '+' is assumed.
1615
1616 If the login name is invalid, or the tilde expansion fails, the word
1617is left unchanged.
1618
1619 Each variable assignment is checked for unquoted tilde-prefixes
1620immediately following a ':' or the first '='. In these cases, tilde
1621expansion is also performed. Consequently, one may use filenames with
1622tildes in assignments to 'PATH', 'MAILPATH', and 'CDPATH', and the shell
1623assigns the expanded value.
1624
1625 The following table shows how Bash treats unquoted tilde-prefixes:
1626
1627'~'
1628 The value of '$HOME'
1629'~/foo'
1630 '$HOME/foo'
1631
1632'~fred/foo'
1633 The subdirectory 'foo' of the home directory of the user 'fred'
1634
1635'~+/foo'
1636 '$PWD/foo'
1637
1638'~-/foo'
1639 '${OLDPWD-'~-'}/foo'
1640
1641'~N'
1642 The string that would be displayed by 'dirs +N'
1643
1644'~+N'
1645 The string that would be displayed by 'dirs +N'
1646
1647'~-N'
1648 The string that would be displayed by 'dirs -N'
1649
d233b485
CR
1650 Bash also performs tilde expansion on words satisfying the conditions
1651of variable assignments (*note Shell Parameters::) when they appear as
1652arguments to simple commands. Bash does not do this, except for the
1653DECLARATION commands listed above, when in POSIX mode.
1654
a0c0a00f
CR
1655\1f
1656File: bash.info, Node: Shell Parameter Expansion, Next: Command Substitution, Prev: Tilde Expansion, Up: Shell Expansions
1657
16583.5.3 Shell Parameter Expansion
1659-------------------------------
1660
1661The '$' character introduces parameter expansion, command substitution,
1662or arithmetic expansion. The parameter name or symbol to be expanded
1663may be enclosed in braces, which are optional but serve to protect the
1664variable to be expanded from characters immediately following it which
1665could be interpreted as part of the name.
1666
1667 When braces are used, the matching ending brace is the first '}' not
1668escaped by a backslash or within a quoted string, and not within an
1669embedded arithmetic expansion, command substitution, or parameter
1670expansion.
1671
1672 The basic form of parameter expansion is ${PARAMETER}. The value of
1673PARAMETER is substituted. The PARAMETER is a shell parameter as
1674described above (*note Shell Parameters::) or an array reference (*note
1675Arrays::). The braces are required when PARAMETER is a positional
1676parameter with more than one digit, or when PARAMETER is followed by a
1677character that is not to be interpreted as part of its name.
1678
1679 If the first character of PARAMETER is an exclamation point (!), and
d233b485
CR
1680PARAMETER is not a NAMEREF, it introduces a level of indirection. Bash
1681uses the value formed by expanding the rest of PARAMETER as the new
1682PARAMETER; this is then expanded and that value is used in the rest of
1683the expansion, rather than the expansion of the original PARAMETER.
1684This is known as 'indirect expansion'. The value is subject to tilde
1685expansion, parameter expansion, command substitution, and arithmetic
1686expansion. If PARAMETER is a nameref, this expands to the name of the
1687variable referenced by PARAMETER instead of performing the complete
1688indirect expansion. The exceptions to this are the expansions of
1689${!PREFIX*} and ${!NAME[@]} described below. The exclamation point must
1690immediately follow the left brace in order to introduce indirection.
a0c0a00f
CR
1691
1692 In each of the cases below, WORD is subject to tilde expansion,
1693parameter expansion, command substitution, and arithmetic expansion.
1694
1695 When not performing substring expansion, using the form described
1696below (e.g., ':-'), Bash tests for a parameter that is unset or null.
1697Omitting the colon results in a test only for a parameter that is unset.
1698Put another way, if the colon is included, the operator tests for both
1699PARAMETER's existence and that its value is not null; if the colon is
1700omitted, the operator tests only for existence.
1701
1702'${PARAMETER:-WORD}'
1703 If PARAMETER is unset or null, the expansion of WORD is
1704 substituted. Otherwise, the value of PARAMETER is substituted.
1705
1706'${PARAMETER:=WORD}'
1707 If PARAMETER is unset or null, the expansion of WORD is assigned to
1708 PARAMETER. The value of PARAMETER is then substituted. Positional
1709 parameters and special parameters may not be assigned to in this
1710 way.
1711
1712'${PARAMETER:?WORD}'
1713 If PARAMETER is null or unset, the expansion of WORD (or a message
1714 to that effect if WORD is not present) is written to the standard
1715 error and the shell, if it is not interactive, exits. Otherwise,
1716 the value of PARAMETER is substituted.
1717
1718'${PARAMETER:+WORD}'
1719 If PARAMETER is null or unset, nothing is substituted, otherwise
1720 the expansion of WORD is substituted.
1721
1722'${PARAMETER:OFFSET}'
1723'${PARAMETER:OFFSET:LENGTH}'
1724 This is referred to as Substring Expansion. It expands to up to
1725 LENGTH characters of the value of PARAMETER starting at the
1726 character specified by OFFSET. If PARAMETER is '@', an indexed
1727 array subscripted by '@' or '*', or an associative array name, the
1728 results differ as described below. If LENGTH is omitted, it
1729 expands to the substring of the value of PARAMETER starting at the
1730 character specified by OFFSET and extending to the end of the
1731 value. LENGTH and OFFSET are arithmetic expressions (*note Shell
1732 Arithmetic::).
1733
1734 If OFFSET evaluates to a number less than zero, the value is used
1735 as an offset in characters from the end of the value of PARAMETER.
1736 If LENGTH evaluates to a number less than zero, it is interpreted
1737 as an offset in characters from the end of the value of PARAMETER
1738 rather than a number of characters, and the expansion is the
1739 characters between OFFSET and that result. Note that a negative
1740 offset must be separated from the colon by at least one space to
1741 avoid being confused with the ':-' expansion.
1742
1743 Here are some examples illustrating substring expansion on
1744 parameters and subscripted arrays:
1745
1746 $ string=01234567890abcdefgh
1747 $ echo ${string:7}
1748 7890abcdefgh
1749 $ echo ${string:7:0}
d233b485 1750
a0c0a00f
CR
1751 $ echo ${string:7:2}
1752 78
1753 $ echo ${string:7:-2}
1754 7890abcdef
1755 $ echo ${string: -7}
1756 bcdefgh
1757 $ echo ${string: -7:0}
d233b485 1758
a0c0a00f
CR
1759 $ echo ${string: -7:2}
1760 bc
1761 $ echo ${string: -7:-2}
1762 bcdef
1763 $ set -- 01234567890abcdefgh
1764 $ echo ${1:7}
1765 7890abcdefgh
1766 $ echo ${1:7:0}
d233b485 1767
a0c0a00f
CR
1768 $ echo ${1:7:2}
1769 78
1770 $ echo ${1:7:-2}
1771 7890abcdef
1772 $ echo ${1: -7}
1773 bcdefgh
1774 $ echo ${1: -7:0}
d233b485 1775
a0c0a00f
CR
1776 $ echo ${1: -7:2}
1777 bc
1778 $ echo ${1: -7:-2}
1779 bcdef
1780 $ array[0]=01234567890abcdefgh
1781 $ echo ${array[0]:7}
1782 7890abcdefgh
1783 $ echo ${array[0]:7:0}
d233b485 1784
a0c0a00f
CR
1785 $ echo ${array[0]:7:2}
1786 78
1787 $ echo ${array[0]:7:-2}
1788 7890abcdef
1789 $ echo ${array[0]: -7}
1790 bcdefgh
1791 $ echo ${array[0]: -7:0}
d233b485 1792
a0c0a00f
CR
1793 $ echo ${array[0]: -7:2}
1794 bc
1795 $ echo ${array[0]: -7:-2}
1796 bcdef
1797
1798 If PARAMETER is '@', the result is LENGTH positional parameters
1799 beginning at OFFSET. A negative OFFSET is taken relative to one
1800 greater than the greatest positional parameter, so an offset of -1
1801 evaluates to the last positional parameter. It is an expansion
1802 error if LENGTH evaluates to a number less than zero.
1803
1804 The following examples illustrate substring expansion using
1805 positional parameters:
1806
1807 $ set -- 1 2 3 4 5 6 7 8 9 0 a b c d e f g h
1808 $ echo ${@:7}
1809 7 8 9 0 a b c d e f g h
1810 $ echo ${@:7:0}
d233b485 1811
a0c0a00f
CR
1812 $ echo ${@:7:2}
1813 7 8
1814 $ echo ${@:7:-2}
1815 bash: -2: substring expression < 0
1816 $ echo ${@: -7:2}
1817 b c
1818 $ echo ${@:0}
1819 ./bash 1 2 3 4 5 6 7 8 9 0 a b c d e f g h
1820 $ echo ${@:0:2}
1821 ./bash 1
1822 $ echo ${@: -7:0}
d233b485 1823
a0c0a00f
CR
1824
1825 If PARAMETER is an indexed array name subscripted by '@' or '*',
1826 the result is the LENGTH members of the array beginning with
1827 '${PARAMETER[OFFSET]}'. A negative OFFSET is taken relative to one
1828 greater than the maximum index of the specified array. It is an
1829 expansion error if LENGTH evaluates to a number less than zero.
1830
1831 These examples show how you can use substring expansion with
1832 indexed arrays:
1833
1834 $ array=(0 1 2 3 4 5 6 7 8 9 0 a b c d e f g h)
1835 $ echo ${array[@]:7}
1836 7 8 9 0 a b c d e f g h
1837 $ echo ${array[@]:7:2}
1838 7 8
1839 $ echo ${array[@]: -7:2}
1840 b c
1841 $ echo ${array[@]: -7:-2}
1842 bash: -2: substring expression < 0
1843 $ echo ${array[@]:0}
1844 0 1 2 3 4 5 6 7 8 9 0 a b c d e f g h
1845 $ echo ${array[@]:0:2}
1846 0 1
1847 $ echo ${array[@]: -7:0}
d233b485 1848
a0c0a00f
CR
1849
1850 Substring expansion applied to an associative array produces
1851 undefined results.
1852
1853 Substring indexing is zero-based unless the positional parameters
1854 are used, in which case the indexing starts at 1 by default. If
1855 OFFSET is 0, and the positional parameters are used, '$@' is
1856 prefixed to the list.
1857
1858'${!PREFIX*}'
1859'${!PREFIX@}'
1860 Expands to the names of variables whose names begin with PREFIX,
1861 separated by the first character of the 'IFS' special variable.
1862 When '@' is used and the expansion appears within double quotes,
1863 each variable name expands to a separate word.
1864
1865'${!NAME[@]}'
1866'${!NAME[*]}'
1867 If NAME is an array variable, expands to the list of array indices
1868 (keys) assigned in NAME. If NAME is not an array, expands to 0 if
1869 NAME is set and null otherwise. When '@' is used and the expansion
1870 appears within double quotes, each key expands to a separate word.
1871
1872'${#PARAMETER}'
1873 The length in characters of the expanded value of PARAMETER is
1874 substituted. If PARAMETER is '*' or '@', the value substituted is
1875 the number of positional parameters. If PARAMETER is an array name
1876 subscripted by '*' or '@', the value substituted is the number of
1877 elements in the array. If PARAMETER is an indexed array name
1878 subscripted by a negative number, that number is interpreted as
1879 relative to one greater than the maximum index of PARAMETER, so
1880 negative indices count back from the end of the array, and an index
1881 of -1 references the last element.
1882
1883'${PARAMETER#WORD}'
1884'${PARAMETER##WORD}'
d233b485
CR
1885 The WORD is expanded to produce a pattern and matched according to
1886 the rules described below (*note Pattern Matching::). If the
1887 pattern matches the beginning of the expanded value of PARAMETER,
1888 then the result of the expansion is the expanded value of PARAMETER
1889 with the shortest matching pattern (the '#' case) or the longest
1890 matching pattern (the '##' case) deleted. If PARAMETER is '@' or
1891 '*', the pattern removal operation is applied to each positional
1892 parameter in turn, and the expansion is the resultant list. If
1893 PARAMETER is an array variable subscripted with '@' or '*', the
1894 pattern removal operation is applied to each member of the array in
1895 turn, and the expansion is the resultant list.
a0c0a00f
CR
1896
1897'${PARAMETER%WORD}'
1898'${PARAMETER%%WORD}'
d233b485
CR
1899 The WORD is expanded to produce a pattern and matched according to
1900 the rules described below (*note Pattern Matching::). If the
1901 pattern matches If the pattern matches a trailing portion of the
a0c0a00f
CR
1902 expanded value of PARAMETER, then the result of the expansion is
1903 the value of PARAMETER with the shortest matching pattern (the '%'
1904 case) or the longest matching pattern (the '%%' case) deleted. If
1905 PARAMETER is '@' or '*', the pattern removal operation is applied
1906 to each positional parameter in turn, and the expansion is the
1907 resultant list. If PARAMETER is an array variable subscripted with
1908 '@' or '*', the pattern removal operation is applied to each member
1909 of the array in turn, and the expansion is the resultant list.
1910
1911'${PARAMETER/PATTERN/STRING}'
1912
1913 The PATTERN is expanded to produce a pattern just as in filename
1914 expansion. PARAMETER is expanded and the longest match of PATTERN
d233b485
CR
1915 against its value is replaced with STRING. The match is performed
1916 according to the rules described below (*note Pattern Matching::).
1917 If PATTERN begins with '/', all matches of PATTERN are replaced
1918 with STRING. Normally only the first match is replaced. If
1919 PATTERN begins with '#', it must match at the beginning of the
1920 expanded value of PARAMETER. If PATTERN begins with '%', it must
1921 match at the end of the expanded value of PARAMETER. If STRING is
1922 null, matches of PATTERN are deleted and the '/' following PATTERN
1923 may be omitted. If the 'nocasematch' shell option (see the
1924 description of 'shopt' in *note The Shopt Builtin::) is enabled,
1925 the match is performed without regard to the case of alphabetic
1926 characters. If PARAMETER is '@' or '*', the substitution operation
1927 is applied to each positional parameter in turn, and the expansion
1928 is the resultant list. If PARAMETER is an array variable
1929 subscripted with '@' or '*', the substitution operation is applied
1930 to each member of the array in turn, and the expansion is the
1931 resultant list.
a0c0a00f
CR
1932
1933'${PARAMETER^PATTERN}'
1934'${PARAMETER^^PATTERN}'
1935'${PARAMETER,PATTERN}'
1936'${PARAMETER,,PATTERN}'
1937 This expansion modifies the case of alphabetic characters in
1938 PARAMETER. The PATTERN is expanded to produce a pattern just as in
1939 filename expansion. Each character in the expanded value of
1940 PARAMETER is tested against PATTERN, and, if it matches the
1941 pattern, its case is converted. The pattern should not attempt to
1942 match more than one character. The '^' operator converts lowercase
1943 letters matching PATTERN to uppercase; the ',' operator converts
1944 matching uppercase letters to lowercase. The '^^' and ',,'
1945 expansions convert each matched character in the expanded value;
1946 the '^' and ',' expansions match and convert only the first
1947 character in the expanded value. If PATTERN is omitted, it is
1948 treated like a '?', which matches every character. If PARAMETER is
1949 '@' or '*', the case modification operation is applied to each
1950 positional parameter in turn, and the expansion is the resultant
1951 list. If PARAMETER is an array variable subscripted with '@' or
1952 '*', the case modification operation is applied to each member of
1953 the array in turn, and the expansion is the resultant list.
1954
1955'${PARAMETER@OPERATOR}'
1956 The expansion is either a transformation of the value of PARAMETER
1957 or information about PARAMETER itself, depending on the value of
1958 OPERATOR. Each OPERATOR is a single letter:
1959
1960 'Q'
1961 The expansion is a string that is the value of PARAMETER
1962 quoted in a format that can be reused as input.
1963 'E'
1964 The expansion is a string that is the value of PARAMETER with
1965 backslash escape sequences expanded as with the '$'...''
d233b485 1966 quoting mechanism.
a0c0a00f
CR
1967 'P'
1968 The expansion is a string that is the result of expanding the
1969 value of PARAMETER as if it were a prompt string (*note
1970 Controlling the Prompt::).
1971 'A'
1972 The expansion is a string in the form of an assignment
1973 statement or 'declare' command that, if evaluated, will
1974 recreate PARAMETER with its attributes and value.
1975 'a'
1976 The expansion is a string consisting of flag values
1977 representing PARAMETER's attributes.
1978
1979 If PARAMETER is '@' or '*', the operation is applied to each
1980 positional parameter in turn, and the expansion is the resultant
1981 list. If PARAMETER is an array variable subscripted with '@' or
1982 '*', the operation is applied to each member of the array in turn,
1983 and the expansion is the resultant list.
1984
1985 The result of the expansion is subject to word splitting and
1986 pathname expansion as described below.
1987
1988\1f
1989File: bash.info, Node: Command Substitution, Next: Arithmetic Expansion, Prev: Shell Parameter Expansion, Up: Shell Expansions
1990
19913.5.4 Command Substitution
1992--------------------------
1993
1994Command substitution allows the output of a command to replace the
1995command itself. Command substitution occurs when a command is enclosed
1996as follows:
1997 $(COMMAND)
1998or
1999 `COMMAND`
2000
2001Bash performs the expansion by executing COMMAND in a subshell
2002environment and replacing the command substitution with the standard
2003output of the command, with any trailing newlines deleted. Embedded
2004newlines are not deleted, but they may be removed during word splitting.
2005The command substitution '$(cat FILE)' can be replaced by the equivalent
2006but faster '$(< FILE)'.
2007
2008 When the old-style backquote form of substitution is used, backslash
2009retains its literal meaning except when followed by '$', '`', or '\'.
2010The first backquote not preceded by a backslash terminates the command
2011substitution. When using the '$(COMMAND)' form, all characters between
2012the parentheses make up the command; none are treated specially.
2013
2014 Command substitutions may be nested. To nest when using the
2015backquoted form, escape the inner backquotes with backslashes.
2016
2017 If the substitution appears within double quotes, word splitting and
2018filename expansion are not performed on the results.
2019
2020\1f
2021File: bash.info, Node: Arithmetic Expansion, Next: Process Substitution, Prev: Command Substitution, Up: Shell Expansions
2022
20233.5.5 Arithmetic Expansion
2024--------------------------
2025
2026Arithmetic expansion allows the evaluation of an arithmetic expression
2027and the substitution of the result. The format for arithmetic expansion
2028is:
2029
2030 $(( EXPRESSION ))
2031
2032 The expression is treated as if it were within double quotes, but a
2033double quote inside the parentheses is not treated specially. All
2034tokens in the expression undergo parameter and variable expansion,
2035command substitution, and quote removal. The result is treated as the
2036arithmetic expression to be evaluated. Arithmetic expansions may be
2037nested.
2038
2039 The evaluation is performed according to the rules listed below
2040(*note Shell Arithmetic::). If the expression is invalid, Bash prints a
2041message indicating failure to the standard error and no substitution
2042occurs.
2043
2044\1f
2045File: bash.info, Node: Process Substitution, Next: Word Splitting, Prev: Arithmetic Expansion, Up: Shell Expansions
2046
20473.5.6 Process Substitution
2048--------------------------
2049
2050Process substitution allows a process's input or output to be referred
2051to using a filename. It takes the form of
2052 <(LIST)
2053or
2054 >(LIST)
2055The process LIST is run asynchronously, and its input or output appears
2056as a filename. This filename is passed as an argument to the current
2057command as the result of the expansion. If the '>(LIST)' form is used,
2058writing to the file will provide input for LIST. If the '<(LIST)' form
2059is used, the file passed as an argument should be read to obtain the
2060output of LIST. Note that no space may appear between the '<' or '>'
2061and the left parenthesis, otherwise the construct would be interpreted
2062as a redirection. Process substitution is supported on systems that
2063support named pipes (FIFOs) or the '/dev/fd' method of naming open
2064files.
2065
2066 When available, process substitution is performed simultaneously with
2067parameter and variable expansion, command substitution, and arithmetic
2068expansion.
2069
2070\1f
2071File: bash.info, Node: Word Splitting, Next: Filename Expansion, Prev: Process Substitution, Up: Shell Expansions
2072
20733.5.7 Word Splitting
2074--------------------
2075
2076The shell scans the results of parameter expansion, command
2077substitution, and arithmetic expansion that did not occur within double
2078quotes for word splitting.
2079
2080 The shell treats each character of '$IFS' as a delimiter, and splits
2081the results of the other expansions into words using these characters as
2082field terminators. If 'IFS' is unset, or its value is exactly
2083'<space><tab><newline>', the default, then sequences of ' <space>',
2084'<tab>', and '<newline>' at the beginning and end of the results of the
2085previous expansions are ignored, and any sequence of 'IFS' characters
2086not at the beginning or end serves to delimit words. If 'IFS' has a
2087value other than the default, then sequences of the whitespace
2088characters 'space', 'tab', and 'newline' are ignored at the beginning
2089and end of the word, as long as the whitespace character is in the value
2090of 'IFS' (an 'IFS' whitespace character). Any character in 'IFS' that
2091is not 'IFS' whitespace, along with any adjacent 'IFS' whitespace
2092characters, delimits a field. A sequence of 'IFS' whitespace characters
2093is also treated as a delimiter. If the value of 'IFS' is null, no word
2094splitting occurs.
2095
2096 Explicit null arguments ('""' or '''') are retained and passed to
2097commands as empty strings. Unquoted implicit null arguments, resulting
2098from the expansion of parameters that have no values, are removed. If a
2099parameter with no value is expanded within double quotes, a null
2100argument results and is retained and passed to a command as an empty
2101string. When a quoted null argument appears as part of a word whose
2102expansion is non-null, the null argument is removed. That is, the word
2103'-d''' becomes '-d' after word splitting and null argument removal.
2104
2105 Note that if no expansion occurs, no splitting is performed.
2106
2107\1f
2108File: bash.info, Node: Filename Expansion, Next: Quote Removal, Prev: Word Splitting, Up: Shell Expansions
2109
21103.5.8 Filename Expansion
2111------------------------
2112
2113* Menu:
2114
2115* Pattern Matching:: How the shell matches patterns.
2116
2117After word splitting, unless the '-f' option has been set (*note The Set
2118Builtin::), Bash scans each word for the characters '*', '?', and '['.
2119If one of these characters appears, then the word is regarded as a
2120PATTERN, and replaced with an alphabetically sorted list of filenames
2121matching the pattern (*note Pattern Matching::). If no matching
2122filenames are found, and the shell option 'nullglob' is disabled, the
2123word is left unchanged. If the 'nullglob' option is set, and no matches
2124are found, the word is removed. If the 'failglob' shell option is set,
2125and no matches are found, an error message is printed and the command is
2126not executed. If the shell option 'nocaseglob' is enabled, the match is
2127performed without regard to the case of alphabetic characters.
2128
2129 When a pattern is used for filename expansion, the character '.' at
2130the start of a filename or immediately following a slash must be matched
d233b485
CR
2131explicitly, unless the shell option 'dotglob' is set. The filenames '.'
2132and '..' must always be matched explicitly, even if 'dotglob' is set.
2133In other cases, the '.' character is not treated specially.
2134
2135 When matching a filename, the slash character must always be matched
2136explicitly by a slash in the pattern, but in other matching contexts it
2137can be matched by a special pattern character as described below (*note
2138Pattern Matching::).
a0c0a00f
CR
2139
2140 See the description of 'shopt' in *note The Shopt Builtin::, for a
2141description of the 'nocaseglob', 'nullglob', 'failglob', and 'dotglob'
2142options.
2143
2144 The 'GLOBIGNORE' shell variable may be used to restrict the set of
d233b485
CR
2145file names matching a pattern. If 'GLOBIGNORE' is set, each matching
2146file name that also matches one of the patterns in 'GLOBIGNORE' is
a0c0a00f
CR
2147removed from the list of matches. If the 'nocaseglob' option is set,
2148the matching against the patterns in 'GLOBIGNORE' is performed without
2149regard to case. The filenames '.' and '..' are always ignored when
2150'GLOBIGNORE' is set and not null. However, setting 'GLOBIGNORE' to a
2151non-null value has the effect of enabling the 'dotglob' shell option, so
2152all other filenames beginning with a '.' will match. To get the old
2153behavior of ignoring filenames beginning with a '.', make '.*' one of
2154the patterns in 'GLOBIGNORE'. The 'dotglob' option is disabled when
2155'GLOBIGNORE' is unset.
2156
2157\1f
2158File: bash.info, Node: Pattern Matching, Up: Filename Expansion
2159
21603.5.8.1 Pattern Matching
2161........................
2162
2163Any character that appears in a pattern, other than the special pattern
2164characters described below, matches itself. The NUL character may not
2165occur in a pattern. A backslash escapes the following character; the
2166escaping backslash is discarded when matching. The special pattern
2167characters must be quoted if they are to be matched literally.
2168
2169 The special pattern characters have the following meanings:
2170'*'
2171 Matches any string, including the null string. When the 'globstar'
2172 shell option is enabled, and '*' is used in a filename expansion
2173 context, two adjacent '*'s used as a single pattern will match all
2174 files and zero or more directories and subdirectories. If followed
2175 by a '/', two adjacent '*'s will match only directories and
2176 subdirectories.
2177'?'
2178 Matches any single character.
2179'[...]'
2180 Matches any one of the enclosed characters. A pair of characters
2181 separated by a hyphen denotes a RANGE EXPRESSION; any character
2182 that falls between those two characters, inclusive, using the
2183 current locale's collating sequence and character set, is matched.
2184 If the first character following the '[' is a '!' or a '^' then any
2185 character not enclosed is matched. A '-' may be matched by
2186 including it as the first or last character in the set. A ']' may
2187 be matched by including it as the first character in the set. The
2188 sorting order of characters in range expressions is determined by
2189 the current locale and the values of the 'LC_COLLATE' and 'LC_ALL'
2190 shell variables, if set.
2191
2192 For example, in the default C locale, '[a-dx-z]' is equivalent to
2193 '[abcdxyz]'. Many locales sort characters in dictionary order, and
2194 in these locales '[a-dx-z]' is typically not equivalent to
2195 '[abcdxyz]'; it might be equivalent to '[aBbCcDdxXyYz]', for
2196 example. To obtain the traditional interpretation of ranges in
2197 bracket expressions, you can force the use of the C locale by
2198 setting the 'LC_COLLATE' or 'LC_ALL' environment variable to the
2199 value 'C', or enable the 'globasciiranges' shell option.
2200
2201 Within '[' and ']', CHARACTER CLASSES can be specified using the
2202 syntax '[:'CLASS':]', where CLASS is one of the following classes
2203 defined in the POSIX standard:
2204 alnum alpha ascii blank cntrl digit graph lower
2205 print punct space upper word xdigit
2206 A character class matches any character belonging to that class.
2207 The 'word' character class matches letters, digits, and the
2208 character '_'.
2209
2210 Within '[' and ']', an EQUIVALENCE CLASS can be specified using the
2211 syntax '[='C'=]', which matches all characters with the same
2212 collation weight (as defined by the current locale) as the
2213 character C.
2214
2215 Within '[' and ']', the syntax '[.'SYMBOL'.]' matches the collating
2216 symbol SYMBOL.
2217
2218 If the 'extglob' shell option is enabled using the 'shopt' builtin,
2219several extended pattern matching operators are recognized. In the
2220following description, a PATTERN-LIST is a list of one or more patterns
2221separated by a '|'. Composite patterns may be formed using one or more
2222of the following sub-patterns:
2223
2224'?(PATTERN-LIST)'
2225 Matches zero or one occurrence of the given patterns.
2226
2227'*(PATTERN-LIST)'
2228 Matches zero or more occurrences of the given patterns.
2229
2230'+(PATTERN-LIST)'
2231 Matches one or more occurrences of the given patterns.
2232
2233'@(PATTERN-LIST)'
2234 Matches one of the given patterns.
2235
2236'!(PATTERN-LIST)'
2237 Matches anything except one of the given patterns.
2238
d233b485
CR
2239 Complicated extended pattern matching against long strings is slow,
2240especially when the patterns contain alternations and the strings
2241contain multiple matches. Using separate matches against shorter
2242strings, or using arrays of strings instead of a single long string, may
2243be faster.
2244
a0c0a00f
CR
2245\1f
2246File: bash.info, Node: Quote Removal, Prev: Filename Expansion, Up: Shell Expansions
2247
22483.5.9 Quote Removal
2249-------------------
2250
2251After the preceding expansions, all unquoted occurrences of the
2252characters '\', ''', and '"' that did not result from one of the above
2253expansions are removed.
2254
2255\1f
2256File: bash.info, Node: Redirections, Next: Executing Commands, Prev: Shell Expansions, Up: Basic Shell Features
2257
22583.6 Redirections
2259================
2260
2261Before a command is executed, its input and output may be REDIRECTED
2262using a special notation interpreted by the shell. Redirection allows
2263commands' file handles to be duplicated, opened, closed, made to refer
2264to different files, and can change the files the command reads from and
2265writes to. Redirection may also be used to modify file handles in the
2266current shell execution environment. The following redirection
2267operators may precede or appear anywhere within a simple command or may
2268follow a command. Redirections are processed in the order they appear,
2269from left to right.
2270
2271 Each redirection that may be preceded by a file descriptor number may
2272instead be preceded by a word of the form {VARNAME}. In this case, for
2273each redirection operator except >&- and <&-, the shell will allocate a
2274file descriptor greater than 10 and assign it to {VARNAME}. If >&- or
2275<&- is preceded by {VARNAME}, the value of VARNAME defines the file
d233b485
CR
2276descriptor to close. If {VARNAME} is supplied, the redirection persists
2277beyond the scope of the command, allowing the shell programmer to manage
2278the file descriptor himself.
a0c0a00f
CR
2279
2280 In the following descriptions, if the file descriptor number is
2281omitted, and the first character of the redirection operator is '<', the
2282redirection refers to the standard input (file descriptor 0). If the
2283first character of the redirection operator is '>', the redirection
2284refers to the standard output (file descriptor 1).
2285
2286 The word following the redirection operator in the following
2287descriptions, unless otherwise noted, is subjected to brace expansion,
2288tilde expansion, parameter expansion, command substitution, arithmetic
2289expansion, quote removal, filename expansion, and word splitting. If it
2290expands to more than one word, Bash reports an error.
2291
2292 Note that the order of redirections is significant. For example, the
2293command
2294 ls > DIRLIST 2>&1
2295directs both standard output (file descriptor 1) and standard error
2296(file descriptor 2) to the file DIRLIST, while the command
2297 ls 2>&1 > DIRLIST
2298directs only the standard output to file DIRLIST, because the standard
2299error was made a copy of the standard output before the standard output
2300was redirected to DIRLIST.
2301
2302 Bash handles several filenames specially when they are used in
2303redirections, as described in the following table. If the operating
2304system on which Bash is running provides these special files, bash will
2305use them; otherwise it will emulate them internally with the behavior
2306described below.
2307
2308'/dev/fd/FD'
2309 If FD is a valid integer, file descriptor FD is duplicated.
2310
2311'/dev/stdin'
2312 File descriptor 0 is duplicated.
2313
2314'/dev/stdout'
2315 File descriptor 1 is duplicated.
2316
2317'/dev/stderr'
2318 File descriptor 2 is duplicated.
2319
2320'/dev/tcp/HOST/PORT'
2321 If HOST is a valid hostname or Internet address, and PORT is an
2322 integer port number or service name, Bash attempts to open the
2323 corresponding TCP socket.
2324
2325'/dev/udp/HOST/PORT'
2326 If HOST is a valid hostname or Internet address, and PORT is an
2327 integer port number or service name, Bash attempts to open the
2328 corresponding UDP socket.
2329
2330 A failure to open or create a file causes the redirection to fail.
2331
2332 Redirections using file descriptors greater than 9 should be used
2333with care, as they may conflict with file descriptors the shell uses
2334internally.
2335
23363.6.1 Redirecting Input
2337-----------------------
2338
2339Redirection of input causes the file whose name results from the
2340expansion of WORD to be opened for reading on file descriptor 'n', or
2341the standard input (file descriptor 0) if 'n' is not specified.
2342
2343 The general format for redirecting input is:
2344 [N]<WORD
2345
23463.6.2 Redirecting Output
2347------------------------
2348
2349Redirection of output causes the file whose name results from the
2350expansion of WORD to be opened for writing on file descriptor N, or the
2351standard output (file descriptor 1) if N is not specified. If the file
2352does not exist it is created; if it does exist it is truncated to zero
2353size.
2354
2355 The general format for redirecting output is:
2356 [N]>[|]WORD
2357
2358 If the redirection operator is '>', and the 'noclobber' option to the
2359'set' builtin has been enabled, the redirection will fail if the file
2360whose name results from the expansion of WORD exists and is a regular
2361file. If the redirection operator is '>|', or the redirection operator
2362is '>' and the 'noclobber' option is not enabled, the redirection is
2363attempted even if the file named by WORD exists.
2364
23653.6.3 Appending Redirected Output
2366---------------------------------
2367
2368Redirection of output in this fashion causes the file whose name results
2369from the expansion of WORD to be opened for appending on file descriptor
2370N, or the standard output (file descriptor 1) if N is not specified. If
2371the file does not exist it is created.
2372
2373 The general format for appending output is:
2374 [N]>>WORD
2375
23763.6.4 Redirecting Standard Output and Standard Error
2377----------------------------------------------------
2378
2379This construct allows both the standard output (file descriptor 1) and
2380the standard error output (file descriptor 2) to be redirected to the
2381file whose name is the expansion of WORD.
2382
2383 There are two formats for redirecting standard output and standard
2384error:
2385 &>WORD
2386and
2387 >&WORD
2388Of the two forms, the first is preferred. This is semantically
2389equivalent to
2390 >WORD 2>&1
2391 When using the second form, WORD may not expand to a number or '-'.
2392If it does, other redirection operators apply (see Duplicating File
2393Descriptors below) for compatibility reasons.
2394
23953.6.5 Appending Standard Output and Standard Error
2396--------------------------------------------------
2397
2398This construct allows both the standard output (file descriptor 1) and
2399the standard error output (file descriptor 2) to be appended to the file
2400whose name is the expansion of WORD.
2401
2402 The format for appending standard output and standard error is:
2403 &>>WORD
2404This is semantically equivalent to
2405 >>WORD 2>&1
2406 (see Duplicating File Descriptors below).
2407
24083.6.6 Here Documents
2409--------------------
2410
2411This type of redirection instructs the shell to read input from the
2412current source until a line containing only WORD (with no trailing
2413blanks) is seen. All of the lines read up to that point are then used
2414as the standard input (or file descriptor N if N is specified) for a
2415command.
2416
2417 The format of here-documents is:
2418 [N]<<[-]WORD
2419 HERE-DOCUMENT
2420 DELIMITER
2421
2422 No parameter and variable expansion, command substitution, arithmetic
2423expansion, or filename expansion is performed on WORD. If any part of
2424WORD is quoted, the DELIMITER is the result of quote removal on WORD,
2425and the lines in the here-document are not expanded. If WORD is
2426unquoted, all lines of the here-document are subjected to parameter
2427expansion, command substitution, and arithmetic expansion, the character
2428sequence '\newline' is ignored, and '\' must be used to quote the
2429characters '\', '$', and '`'.
2430
2431 If the redirection operator is '<<-', then all leading tab characters
2432are stripped from input lines and the line containing DELIMITER. This
2433allows here-documents within shell scripts to be indented in a natural
2434fashion.
2435
24363.6.7 Here Strings
2437------------------
2438
2439A variant of here documents, the format is:
2440 [N]<<< WORD
2441
d233b485
CR
2442 The WORD undergoes tilde expansion, parameter and variable expansion,
2443command substitution, arithmetic expansion, and quote removal. Pathname
2444expansion and word splitting are not performed. The result is supplied
2445as a single string, with a newline appended, to the command on its
2446standard input (or file descriptor N if N is specified).
a0c0a00f
CR
2447
24483.6.8 Duplicating File Descriptors
2449----------------------------------
2450
2451The redirection operator
2452 [N]<&WORD
2453is used to duplicate input file descriptors. If WORD expands to one or
2454more digits, the file descriptor denoted by N is made to be a copy of
2455that file descriptor. If the digits in WORD do not specify a file
2456descriptor open for input, a redirection error occurs. If WORD
2457evaluates to '-', file descriptor N is closed. If N is not specified,
2458the standard input (file descriptor 0) is used.
2459
2460 The operator
2461 [N]>&WORD
2462is used similarly to duplicate output file descriptors. If N is not
2463specified, the standard output (file descriptor 1) is used. If the
2464digits in WORD do not specify a file descriptor open for output, a
2465redirection error occurs. If WORD evaluates to '-', file descriptor N
2466is closed. As a special case, if N is omitted, and WORD does not expand
2467to one or more digits or '-', the standard output and standard error are
2468redirected as described previously.
2469
24703.6.9 Moving File Descriptors
2471-----------------------------
2472
2473The redirection operator
2474 [N]<&DIGIT-
2475moves the file descriptor DIGIT to file descriptor N, or the standard
2476input (file descriptor 0) if N is not specified. DIGIT is closed after
2477being duplicated to N.
2478
2479 Similarly, the redirection operator
2480 [N]>&DIGIT-
2481moves the file descriptor DIGIT to file descriptor N, or the standard
2482output (file descriptor 1) if N is not specified.
2483
24843.6.10 Opening File Descriptors for Reading and Writing
2485-------------------------------------------------------
2486
2487The redirection operator
2488 [N]<>WORD
2489causes the file whose name is the expansion of WORD to be opened for
2490both reading and writing on file descriptor N, or on file descriptor 0
2491if N is not specified. If the file does not exist, it is created.
2492
2493\1f
2494File: bash.info, Node: Executing Commands, Next: Shell Scripts, Prev: Redirections, Up: Basic Shell Features
2495
24963.7 Executing Commands
2497======================
2498
2499* Menu:
2500
2501* Simple Command Expansion:: How Bash expands simple commands before
2502 executing them.
2503* Command Search and Execution:: How Bash finds commands and runs them.
2504* Command Execution Environment:: The environment in which Bash
2505 executes commands that are not
2506 shell builtins.
2507* Environment:: The environment given to a command.
2508* Exit Status:: The status returned by commands and how Bash
2509 interprets it.
2510* Signals:: What happens when Bash or a command it runs
2511 receives a signal.
2512
2513\1f
2514File: bash.info, Node: Simple Command Expansion, Next: Command Search and Execution, Up: Executing Commands
2515
25163.7.1 Simple Command Expansion
2517------------------------------
2518
2519When a simple command is executed, the shell performs the following
2520expansions, assignments, and redirections, from left to right.
2521
2522 1. The words that the parser has marked as variable assignments (those
2523 preceding the command name) and redirections are saved for later
2524 processing.
2525
2526 2. The words that are not variable assignments or redirections are
2527 expanded (*note Shell Expansions::). If any words remain after
2528 expansion, the first word is taken to be the name of the command
2529 and the remaining words are the arguments.
2530
2531 3. Redirections are performed as described above (*note
2532 Redirections::).
2533
2534 4. The text after the '=' in each variable assignment undergoes tilde
2535 expansion, parameter expansion, command substitution, arithmetic
2536 expansion, and quote removal before being assigned to the variable.
2537
2538 If no command name results, the variable assignments affect the
2539current shell environment. Otherwise, the variables are added to the
2540environment of the executed command and do not affect the current shell
2541environment. If any of the assignments attempts to assign a value to a
2542readonly variable, an error occurs, and the command exits with a
2543non-zero status.
2544
2545 If no command name results, redirections are performed, but do not
2546affect the current shell environment. A redirection error causes the
2547command to exit with a non-zero status.
2548
2549 If there is a command name left after expansion, execution proceeds
2550as described below. Otherwise, the command exits. If one of the
2551expansions contained a command substitution, the exit status of the
2552command is the exit status of the last command substitution performed.
2553If there were no command substitutions, the command exits with a status
2554of zero.
2555
2556\1f
2557File: bash.info, Node: Command Search and Execution, Next: Command Execution Environment, Prev: Simple Command Expansion, Up: Executing Commands
2558
25593.7.2 Command Search and Execution
2560----------------------------------
2561
2562After a command has been split into words, if it results in a simple
2563command and an optional list of arguments, the following actions are
2564taken.
2565
2566 1. If the command name contains no slashes, the shell attempts to
2567 locate it. If there exists a shell function by that name, that
2568 function is invoked as described in *note Shell Functions::.
2569
2570 2. If the name does not match a function, the shell searches for it in
2571 the list of shell builtins. If a match is found, that builtin is
2572 invoked.
2573
2574 3. If the name is neither a shell function nor a builtin, and contains
2575 no slashes, Bash searches each element of '$PATH' for a directory
2576 containing an executable file by that name. Bash uses a hash table
2577 to remember the full pathnames of executable files to avoid
2578 multiple 'PATH' searches (see the description of 'hash' in *note
2579 Bourne Shell Builtins::). A full search of the directories in
2580 '$PATH' is performed only if the command is not found in the hash
2581 table. If the search is unsuccessful, the shell searches for a
2582 defined shell function named 'command_not_found_handle'. If that
d233b485
CR
2583 function exists, it is invoked in a separate execution environment
2584 with the original command and the original command's arguments as
2585 its arguments, and the function's exit status becomes the exit
2586 status of that subshell. If that function is not defined, the
2587 shell prints an error message and returns an exit status of 127.
a0c0a00f
CR
2588
2589 4. If the search is successful, or if the command name contains one or
2590 more slashes, the shell executes the named program in a separate
2591 execution environment. Argument 0 is set to the name given, and
2592 the remaining arguments to the command are set to the arguments
2593 supplied, if any.
2594
2595 5. If this execution fails because the file is not in executable
2596 format, and the file is not a directory, it is assumed to be a
2597 SHELL SCRIPT and the shell executes it as described in *note Shell
2598 Scripts::.
2599
2600 6. If the command was not begun asynchronously, the shell waits for
2601 the command to complete and collects its exit status.
2602
2603\1f
2604File: bash.info, Node: Command Execution Environment, Next: Environment, Prev: Command Search and Execution, Up: Executing Commands
2605
26063.7.3 Command Execution Environment
2607-----------------------------------
2608
2609The shell has an EXECUTION ENVIRONMENT, which consists of the following:
2610
2611 * open files inherited by the shell at invocation, as modified by
2612 redirections supplied to the 'exec' builtin
2613
2614 * the current working directory as set by 'cd', 'pushd', or 'popd',
2615 or inherited by the shell at invocation
2616
2617 * the file creation mode mask as set by 'umask' or inherited from the
2618 shell's parent
2619
2620 * current traps set by 'trap'
2621
2622 * shell parameters that are set by variable assignment or with 'set'
2623 or inherited from the shell's parent in the environment
2624
2625 * shell functions defined during execution or inherited from the
2626 shell's parent in the environment
2627
2628 * options enabled at invocation (either by default or with
2629 command-line arguments) or by 'set'
2630
2631 * options enabled by 'shopt' (*note The Shopt Builtin::)
2632
2633 * shell aliases defined with 'alias' (*note Aliases::)
2634
2635 * various process IDs, including those of background jobs (*note
2636 Lists::), the value of '$$', and the value of '$PPID'
2637
2638 When a simple command other than a builtin or shell function is to be
2639executed, it is invoked in a separate execution environment that
2640consists of the following. Unless otherwise noted, the values are
2641inherited from the shell.
2642
2643 * the shell's open files, plus any modifications and additions
2644 specified by redirections to the command
2645
2646 * the current working directory
2647
2648 * the file creation mode mask
2649
2650 * shell variables and functions marked for export, along with
2651 variables exported for the command, passed in the environment
2652 (*note Environment::)
2653
2654 * traps caught by the shell are reset to the values inherited from
2655 the shell's parent, and traps ignored by the shell are ignored
2656
2657 A command invoked in this separate environment cannot affect the
2658shell's execution environment.
2659
2660 Command substitution, commands grouped with parentheses, and
2661asynchronous commands are invoked in a subshell environment that is a
2662duplicate of the shell environment, except that traps caught by the
2663shell are reset to the values that the shell inherited from its parent
2664at invocation. Builtin commands that are invoked as part of a pipeline
2665are also executed in a subshell environment. Changes made to the
2666subshell environment cannot affect the shell's execution environment.
2667
2668 Subshells spawned to execute command substitutions inherit the value
2669of the '-e' option from the parent shell. When not in POSIX mode, Bash
2670clears the '-e' option in such subshells.
2671
2672 If a command is followed by a '&' and job control is not active, the
2673default standard input for the command is the empty file '/dev/null'.
2674Otherwise, the invoked command inherits the file descriptors of the
2675calling shell as modified by redirections.
2676
2677\1f
2678File: bash.info, Node: Environment, Next: Exit Status, Prev: Command Execution Environment, Up: Executing Commands
2679
26803.7.4 Environment
2681-----------------
2682
2683When a program is invoked it is given an array of strings called the
2684ENVIRONMENT. This is a list of name-value pairs, of the form
2685'name=value'.
2686
2687 Bash provides several ways to manipulate the environment. On
2688invocation, the shell scans its own environment and creates a parameter
2689for each name found, automatically marking it for EXPORT to child
2690processes. Executed commands inherit the environment. The 'export' and
2691'declare -x' commands allow parameters and functions to be added to and
2692deleted from the environment. If the value of a parameter in the
2693environment is modified, the new value becomes part of the environment,
2694replacing the old. The environment inherited by any executed command
2695consists of the shell's initial environment, whose values may be
2696modified in the shell, less any pairs removed by the 'unset' and 'export
2697-n' commands, plus any additions via the 'export' and 'declare -x'
2698commands.
2699
2700 The environment for any simple command or function may be augmented
2701temporarily by prefixing it with parameter assignments, as described in
2702*note Shell Parameters::. These assignment statements affect only the
2703environment seen by that command.
2704
2705 If the '-k' option is set (*note The Set Builtin::), then all
2706parameter assignments are placed in the environment for a command, not
2707just those that precede the command name.
2708
2709 When Bash invokes an external command, the variable '$_' is set to
2710the full pathname of the command and passed to that command in its
2711environment.
2712
2713\1f
2714File: bash.info, Node: Exit Status, Next: Signals, Prev: Environment, Up: Executing Commands
2715
27163.7.5 Exit Status
2717-----------------
2718
2719The exit status of an executed command is the value returned by the
2720WAITPID system call or equivalent function. Exit statuses fall between
27210 and 255, though, as explained below, the shell may use values above
2722125 specially. Exit statuses from shell builtins and compound commands
2723are also limited to this range. Under certain circumstances, the shell
2724will use special values to indicate specific failure modes.
2725
2726 For the shell's purposes, a command which exits with a zero exit
2727status has succeeded. A non-zero exit status indicates failure. This
2728seemingly counter-intuitive scheme is used so there is one well-defined
2729way to indicate success and a variety of ways to indicate various
2730failure modes. When a command terminates on a fatal signal whose number
2731is N, Bash uses the value 128+N as the exit status.
2732
2733 If a command is not found, the child process created to execute it
2734returns a status of 127. If a command is found but is not executable,
2735the return status is 126.
2736
2737 If a command fails because of an error during expansion or
2738redirection, the exit status is greater than zero.
2739
2740 The exit status is used by the Bash conditional commands (*note
2741Conditional Constructs::) and some of the list constructs (*note
2742Lists::).
2743
2744 All of the Bash builtins return an exit status of zero if they
2745succeed and a non-zero status on failure, so they may be used by the
2746conditional and list constructs. All builtins return an exit status of
27472 to indicate incorrect usage, generally invalid options or missing
2748arguments.
2749
2750\1f
2751File: bash.info, Node: Signals, Prev: Exit Status, Up: Executing Commands
2752
27533.7.6 Signals
2754-------------
2755
2756When Bash is interactive, in the absence of any traps, it ignores
2757'SIGTERM' (so that 'kill 0' does not kill an interactive shell), and
2758'SIGINT' is caught and handled (so that the 'wait' builtin is
2759interruptible). When Bash receives a 'SIGINT', it breaks out of any
2760executing loops. In all cases, Bash ignores 'SIGQUIT'. If job control
2761is in effect (*note Job Control::), Bash ignores 'SIGTTIN', 'SIGTTOU',
2762and 'SIGTSTP'.
2763
2764 Non-builtin commands started by Bash have signal handlers set to the
2765values inherited by the shell from its parent. When job control is not
2766in effect, asynchronous commands ignore 'SIGINT' and 'SIGQUIT' in
2767addition to these inherited handlers. Commands run as a result of
2768command substitution ignore the keyboard-generated job control signals
2769'SIGTTIN', 'SIGTTOU', and 'SIGTSTP'.
2770
2771 The shell exits by default upon receipt of a 'SIGHUP'. Before
2772exiting, an interactive shell resends the 'SIGHUP' to all jobs, running
2773or stopped. Stopped jobs are sent 'SIGCONT' to ensure that they receive
2774the 'SIGHUP'. To prevent the shell from sending the 'SIGHUP' signal to
2775a particular job, it should be removed from the jobs table with the
2776'disown' builtin (*note Job Control Builtins::) or marked to not receive
2777'SIGHUP' using 'disown -h'.
2778
2779 If the 'huponexit' shell option has been set with 'shopt' (*note The
2780Shopt Builtin::), Bash sends a 'SIGHUP' to all jobs when an interactive
2781login shell exits.
2782
2783 If Bash is waiting for a command to complete and receives a signal
2784for which a trap has been set, the trap will not be executed until the
2785command completes. When Bash is waiting for an asynchronous command via
2786the 'wait' builtin, the reception of a signal for which a trap has been
2787set will cause the 'wait' builtin to return immediately with an exit
2788status greater than 128, immediately after which the trap is executed.
2789
2790\1f
2791File: bash.info, Node: Shell Scripts, Prev: Executing Commands, Up: Basic Shell Features
2792
27933.8 Shell Scripts
2794=================
2795
2796A shell script is a text file containing shell commands. When such a
2797file is used as the first non-option argument when invoking Bash, and
2798neither the '-c' nor '-s' option is supplied (*note Invoking Bash::),
2799Bash reads and executes commands from the file, then exits. This mode
2800of operation creates a non-interactive shell. The shell first searches
2801for the file in the current directory, and looks in the directories in
2802'$PATH' if not found there.
2803
2804 When Bash runs a shell script, it sets the special parameter '0' to
2805the name of the file, rather than the name of the shell, and the
2806positional parameters are set to the remaining arguments, if any are
2807given. If no additional arguments are supplied, the positional
2808parameters are unset.
2809
2810 A shell script may be made executable by using the 'chmod' command to
2811turn on the execute bit. When Bash finds such a file while searching
2812the '$PATH' for a command, it spawns a subshell to execute it. In other
2813words, executing
2814 filename ARGUMENTS
2815is equivalent to executing
2816 bash filename ARGUMENTS
2817
2818if 'filename' is an executable shell script. This subshell
2819reinitializes itself, so that the effect is as if a new shell had been
2820invoked to interpret the script, with the exception that the locations
2821of commands remembered by the parent (see the description of 'hash' in
2822*note Bourne Shell Builtins::) are retained by the child.
2823
2824 Most versions of Unix make this a part of the operating system's
2825command execution mechanism. If the first line of a script begins with
2826the two characters '#!', the remainder of the line specifies an
2827interpreter for the program. Thus, you can specify Bash, 'awk', Perl,
2828or some other interpreter and write the rest of the script file in that
2829language.
2830
2831 The arguments to the interpreter consist of a single optional
2832argument following the interpreter name on the first line of the script
2833file, followed by the name of the script file, followed by the rest of
2834the arguments. Bash will perform this action on operating systems that
2835do not handle it themselves. Note that some older versions of Unix
2836limit the interpreter name and argument to a maximum of 32 characters.
2837
2838 Bash scripts often begin with '#! /bin/bash' (assuming that Bash has
2839been installed in '/bin'), since this ensures that Bash will be used to
2840interpret the script, even if it is executed under another shell.
2841
2842\1f
2843File: bash.info, Node: Shell Builtin Commands, Next: Shell Variables, Prev: Basic Shell Features, Up: Top
2844
28454 Shell Builtin Commands
2846************************
2847
2848* Menu:
2849
2850* Bourne Shell Builtins:: Builtin commands inherited from the Bourne
2851 Shell.
2852* Bash Builtins:: Table of builtins specific to Bash.
2853* Modifying Shell Behavior:: Builtins to modify shell attributes and
2854 optional behavior.
2855* Special Builtins:: Builtin commands classified specially by
2856 POSIX.
2857
2858Builtin commands are contained within the shell itself. When the name
2859of a builtin command is used as the first word of a simple command
2860(*note Simple Commands::), the shell executes the command directly,
2861without invoking another program. Builtin commands are necessary to
2862implement functionality impossible or inconvenient to obtain with
2863separate utilities.
2864
2865 This section briefly describes the builtins which Bash inherits from
2866the Bourne Shell, as well as the builtin commands which are unique to or
2867have been extended in Bash.
2868
2869 Several builtin commands are described in other chapters: builtin
2870commands which provide the Bash interface to the job control facilities
2871(*note Job Control Builtins::), the directory stack (*note Directory
2872Stack Builtins::), the command history (*note Bash History Builtins::),
2873and the programmable completion facilities (*note Programmable
2874Completion Builtins::).
2875
2876 Many of the builtins have been extended by POSIX or Bash.
2877
2878 Unless otherwise noted, each builtin command documented as accepting
2879options preceded by '-' accepts '--' to signify the end of the options.
d233b485
CR
2880The ':', 'true', 'false', and 'test'/'[' builtins do not accept options
2881and do not treat '--' specially. The 'exit', 'logout', 'return',
2882'break', 'continue', 'let', and 'shift' builtins accept and process
2883arguments beginning with '-' without requiring '--'. Other builtins
2884that accept arguments but are not specified as accepting options
2885interpret arguments beginning with '-' as invalid options and require
2886'--' to prevent this interpretation.
a0c0a00f
CR
2887
2888\1f
2889File: bash.info, Node: Bourne Shell Builtins, Next: Bash Builtins, Up: Shell Builtin Commands
2890
28914.1 Bourne Shell Builtins
2892=========================
2893
2894The following shell builtin commands are inherited from the Bourne
2895Shell. These commands are implemented as specified by the POSIX
2896standard.
2897
2898': (a colon)'
2899 : [ARGUMENTS]
2900
2901 Do nothing beyond expanding ARGUMENTS and performing redirections.
2902 The return status is zero.
2903
2904'. (a period)'
2905 . FILENAME [ARGUMENTS]
2906
2907 Read and execute commands from the FILENAME argument in the current
2908 shell context. If FILENAME does not contain a slash, the 'PATH'
2909 variable is used to find FILENAME. When Bash is not in POSIX mode,
2910 the current directory is searched if FILENAME is not found in
2911 '$PATH'. If any ARGUMENTS are supplied, they become the positional
2912 parameters when FILENAME is executed. Otherwise the positional
2913 parameters are unchanged. If the '-T' option is enabled, 'source'
2914 inherits any trap on 'DEBUG'; if it is not, any 'DEBUG' trap string
2915 is saved and restored around the call to 'source', and 'source'
2916 unsets the 'DEBUG' trap while it executes. If '-T' is not set, and
2917 the sourced file changes the 'DEBUG' trap, the new value is
2918 retained when 'source' completes. The return status is the exit
2919 status of the last command executed, or zero if no commands are
2920 executed. If FILENAME is not found, or cannot be read, the return
2921 status is non-zero. This builtin is equivalent to 'source'.
2922
2923'break'
2924 break [N]
2925
2926 Exit from a 'for', 'while', 'until', or 'select' loop. If N is
2927 supplied, the Nth enclosing loop is exited. N must be greater than
2928 or equal to 1. The return status is zero unless N is not greater
2929 than or equal to 1.
2930
2931'cd'
2932 cd [-L|[-P [-e]] [-@] [DIRECTORY]
2933
2934 Change the current working directory to DIRECTORY. If DIRECTORY is
2935 not supplied, the value of the 'HOME' shell variable is used. Any
2936 additional arguments following DIRECTORY are ignored. If the shell
2937 variable 'CDPATH' exists, it is used as a search path: each
2938 directory name in 'CDPATH' is searched for DIRECTORY, with
2939 alternative directory names in 'CDPATH' separated by a colon (':').
2940 If DIRECTORY begins with a slash, 'CDPATH' is not used.
2941
2942 The '-P' option means to not follow symbolic links: symbolic links
2943 are resolved while 'cd' is traversing DIRECTORY and before
2944 processing an instance of '..' in DIRECTORY.
2945
2946 By default, or when the '-L' option is supplied, symbolic links in
2947 DIRECTORY are resolved after 'cd' processes an instance of '..' in
2948 DIRECTORY.
2949
2950 If '..' appears in DIRECTORY, it is processed by removing the
2951 immediately preceding pathname component, back to a slash or the
2952 beginning of DIRECTORY.
2953
2954 If the '-e' option is supplied with '-P' and the current working
2955 directory cannot be successfully determined after a successful
2956 directory change, 'cd' will return an unsuccessful status.
2957
2958 On systems that support it, the '-@' option presents the extended
2959 attributes associated with a file as a directory.
2960
2961 If DIRECTORY is '-', it is converted to '$OLDPWD' before the
2962 directory change is attempted.
2963
2964 If a non-empty directory name from 'CDPATH' is used, or if '-' is
2965 the first argument, and the directory change is successful, the
2966 absolute pathname of the new working directory is written to the
2967 standard output.
2968
2969 The return status is zero if the directory is successfully changed,
2970 non-zero otherwise.
2971
2972'continue'
2973 continue [N]
2974
2975 Resume the next iteration of an enclosing 'for', 'while', 'until',
2976 or 'select' loop. If N is supplied, the execution of the Nth
2977 enclosing loop is resumed. N must be greater than or equal to 1.
2978 The return status is zero unless N is not greater than or equal to
2979 1.
2980
2981'eval'
2982 eval [ARGUMENTS]
2983
2984 The arguments are concatenated together into a single command,
2985 which is then read and executed, and its exit status returned as
2986 the exit status of 'eval'. If there are no arguments or only empty
2987 arguments, the return status is zero.
2988
2989'exec'
2990 exec [-cl] [-a NAME] [COMMAND [ARGUMENTS]]
2991
2992 If COMMAND is supplied, it replaces the shell without creating a
2993 new process. If the '-l' option is supplied, the shell places a
2994 dash at the beginning of the zeroth argument passed to COMMAND.
2995 This is what the 'login' program does. The '-c' option causes
2996 COMMAND to be executed with an empty environment. If '-a' is
2997 supplied, the shell passes NAME as the zeroth argument to COMMAND.
2998 If COMMAND cannot be executed for some reason, a non-interactive
2999 shell exits, unless the 'execfail' shell option is enabled. In
3000 that case, it returns failure. An interactive shell returns
d233b485
CR
3001 failure if the file cannot be executed. A subshell exits
3002 unconditionally if 'exec' fails. If no COMMAND is specified,
3003 redirections may be used to affect the current shell environment.
3004 If there are no redirection errors, the return status is zero;
3005 otherwise the return status is non-zero.
a0c0a00f
CR
3006
3007'exit'
3008 exit [N]
3009
3010 Exit the shell, returning a status of N to the shell's parent. If
3011 N is omitted, the exit status is that of the last command executed.
3012 Any trap on 'EXIT' is executed before the shell terminates.
3013
3014'export'
3015 export [-fn] [-p] [NAME[=VALUE]]
3016
3017 Mark each NAME to be passed to child processes in the environment.
3018 If the '-f' option is supplied, the NAMEs refer to shell functions;
3019 otherwise the names refer to shell variables. The '-n' option
3020 means to no longer mark each NAME for export. If no NAMES are
3021 supplied, or if the '-p' option is given, a list of names of all
3022 exported variables is displayed. The '-p' option displays output
3023 in a form that may be reused as input. If a variable name is
3024 followed by =VALUE, the value of the variable is set to VALUE.
3025
3026 The return status is zero unless an invalid option is supplied, one
3027 of the names is not a valid shell variable name, or '-f' is
3028 supplied with a name that is not a shell function.
3029
3030'getopts'
3031 getopts OPTSTRING NAME [ARGS]
3032
3033 'getopts' is used by shell scripts to parse positional parameters.
3034 OPTSTRING contains the option characters to be recognized; if a
3035 character is followed by a colon, the option is expected to have an
3036 argument, which should be separated from it by whitespace. The
3037 colon (':') and question mark ('?') may not be used as option
3038 characters. Each time it is invoked, 'getopts' places the next
3039 option in the shell variable NAME, initializing NAME if it does not
3040 exist, and the index of the next argument to be processed into the
3041 variable 'OPTIND'. 'OPTIND' is initialized to 1 each time the
3042 shell or a shell script is invoked. When an option requires an
3043 argument, 'getopts' places that argument into the variable
3044 'OPTARG'. The shell does not reset 'OPTIND' automatically; it must
3045 be manually reset between multiple calls to 'getopts' within the
3046 same shell invocation if a new set of parameters is to be used.
3047
3048 When the end of options is encountered, 'getopts' exits with a
3049 return value greater than zero. 'OPTIND' is set to the index of
3050 the first non-option argument, and NAME is set to '?'.
3051
3052 'getopts' normally parses the positional parameters, but if more
3053 arguments are given in ARGS, 'getopts' parses those instead.
3054
3055 'getopts' can report errors in two ways. If the first character of
3056 OPTSTRING is a colon, SILENT error reporting is used. In normal
3057 operation, diagnostic messages are printed when invalid options or
3058 missing option arguments are encountered. If the variable 'OPTERR'
3059 is set to 0, no error messages will be displayed, even if the first
3060 character of 'optstring' is not a colon.
3061
3062 If an invalid option is seen, 'getopts' places '?' into NAME and,
3063 if not silent, prints an error message and unsets 'OPTARG'. If
3064 'getopts' is silent, the option character found is placed in
3065 'OPTARG' and no diagnostic message is printed.
3066
3067 If a required argument is not found, and 'getopts' is not silent, a
3068 question mark ('?') is placed in NAME, 'OPTARG' is unset, and a
3069 diagnostic message is printed. If 'getopts' is silent, then a
3070 colon (':') is placed in NAME and 'OPTARG' is set to the option
3071 character found.
3072
3073'hash'
3074 hash [-r] [-p FILENAME] [-dt] [NAME]
3075
3076 Each time 'hash' is invoked, it remembers the full pathnames of the
3077 commands specified as NAME arguments, so they need not be searched
3078 for on subsequent invocations. The commands are found by searching
3079 through the directories listed in '$PATH'. Any
3080 previously-remembered pathname is discarded. The '-p' option
3081 inhibits the path search, and FILENAME is used as the location of
3082 NAME. The '-r' option causes the shell to forget all remembered
3083 locations. The '-d' option causes the shell to forget the
3084 remembered location of each NAME. If the '-t' option is supplied,
3085 the full pathname to which each NAME corresponds is printed. If
d233b485 3086 multiple NAME arguments are supplied with '-t', the NAME is printed
a0c0a00f
CR
3087 before the hashed full pathname. The '-l' option causes output to
3088 be displayed in a format that may be reused as input. If no
3089 arguments are given, or if only '-l' is supplied, information about
3090 remembered commands is printed. The return status is zero unless a
3091 NAME is not found or an invalid option is supplied.
3092
3093'pwd'
3094 pwd [-LP]
3095
3096 Print the absolute pathname of the current working directory. If
3097 the '-P' option is supplied, the pathname printed will not contain
3098 symbolic links. If the '-L' option is supplied, the pathname
3099 printed may contain symbolic links. The return status is zero
3100 unless an error is encountered while determining the name of the
3101 current directory or an invalid option is supplied.
3102
3103'readonly'
3104 readonly [-aAf] [-p] [NAME[=VALUE]] ...
3105
3106 Mark each NAME as readonly. The values of these names may not be
3107 changed by subsequent assignment. If the '-f' option is supplied,
3108 each NAME refers to a shell function. The '-a' option means each
3109 NAME refers to an indexed array variable; the '-A' option means
3110 each NAME refers to an associative array variable. If both options
3111 are supplied, '-A' takes precedence. If no NAME arguments are
3112 given, or if the '-p' option is supplied, a list of all readonly
3113 names is printed. The other options may be used to restrict the
3114 output to a subset of the set of readonly names. The '-p' option
3115 causes output to be displayed in a format that may be reused as
3116 input. If a variable name is followed by =VALUE, the value of the
3117 variable is set to VALUE. The return status is zero unless an
3118 invalid option is supplied, one of the NAME arguments is not a
3119 valid shell variable or function name, or the '-f' option is
3120 supplied with a name that is not a shell function.
3121
3122'return'
3123 return [N]
3124
3125 Cause a shell function to stop executing and return the value N to
3126 its caller. If N is not supplied, the return value is the exit
3127 status of the last command executed in the function. If 'return'
3128 is executed by a trap handler, the last command used to determine
3129 the status is the last command executed before the trap handler.
d233b485 3130 If 'return' is executed during a 'DEBUG' trap, the last command
a0c0a00f
CR
3131 used to determine the status is the last command executed by the
3132 trap handler before 'return' was invoked. 'return' may also be
3133 used to terminate execution of a script being executed with the '.'
3134 ('source') builtin, returning either N or the exit status of the
3135 last command executed within the script as the exit status of the
3136 script. If N is supplied, the return value is its least
3137 significant 8 bits. Any command associated with the 'RETURN' trap
3138 is executed before execution resumes after the function or script.
3139 The return status is non-zero if 'return' is supplied a non-numeric
3140 argument or is used outside a function and not during the execution
3141 of a script by '.' or 'source'.
3142
3143'shift'
3144 shift [N]
3145
3146 Shift the positional parameters to the left by N. The positional
3147 parameters from N+1 ... '$#' are renamed to '$1' ... '$#'-N.
3148 Parameters represented by the numbers '$#' to '$#'-N+1 are unset.
3149 N must be a non-negative number less than or equal to '$#'. If N
3150 is zero or greater than '$#', the positional parameters are not
3151 changed. If N is not supplied, it is assumed to be 1. The return
3152 status is zero unless N is greater than '$#' or less than zero,
3153 non-zero otherwise.
3154
3155'test'
3156'['
3157 test EXPR
3158
3159 Evaluate a conditional expression EXPR and return a status of 0
3160 (true) or 1 (false). Each operator and operand must be a separate
3161 argument. Expressions are composed of the primaries described
3162 below in *note Bash Conditional Expressions::. 'test' does not
3163 accept any options, nor does it accept and ignore an argument of
3164 '--' as signifying the end of options.
3165
3166 When the '[' form is used, the last argument to the command must be
3167 a ']'.
3168
3169 Expressions may be combined using the following operators, listed
3170 in decreasing order of precedence. The evaluation depends on the
3171 number of arguments; see below. Operator precedence is used when
3172 there are five or more arguments.
3173
3174 '! EXPR'
3175 True if EXPR is false.
3176
3177 '( EXPR )'
3178 Returns the value of EXPR. This may be used to override the
3179 normal precedence of operators.
3180
3181 'EXPR1 -a EXPR2'
3182 True if both EXPR1 and EXPR2 are true.
3183
3184 'EXPR1 -o EXPR2'
3185 True if either EXPR1 or EXPR2 is true.
3186
3187 The 'test' and '[' builtins evaluate conditional expressions using
3188 a set of rules based on the number of arguments.
3189
3190 0 arguments
3191 The expression is false.
3192
3193 1 argument
d233b485 3194 The expression is true if, and only if, the argument is not
a0c0a00f
CR
3195 null.
3196
3197 2 arguments
3198 If the first argument is '!', the expression is true if and
3199 only if the second argument is null. If the first argument is
3200 one of the unary conditional operators (*note Bash Conditional
3201 Expressions::), the expression is true if the unary test is
3202 true. If the first argument is not a valid unary operator,
3203 the expression is false.
3204
3205 3 arguments
d233b485
CR
3206 The following conditions are applied in the order listed.
3207
3208 1. If the second argument is one of the binary conditional
3209 operators (*note Bash Conditional Expressions::), the
3210 result of the expression is the result of the binary test
3211 using the first and third arguments as operands. The
3212 '-a' and '-o' operators are considered binary operators
3213 when there are three arguments.
3214 2. If the first argument is '!', the value is the negation
3215 of the two-argument test using the second and third
3216 arguments.
3217 3. If the first argument is exactly '(' and the third
3218 argument is exactly ')', the result is the one-argument
3219 test of the second argument.
3220 4. Otherwise, the expression is false.
a0c0a00f
CR
3221
3222 4 arguments
3223 If the first argument is '!', the result is the negation of
3224 the three-argument expression composed of the remaining
3225 arguments. Otherwise, the expression is parsed and evaluated
3226 according to precedence using the rules listed above.
3227
3228 5 or more arguments
3229 The expression is parsed and evaluated according to precedence
3230 using the rules listed above.
3231
3232 When used with 'test' or '[', the '<' and '>' operators sort
3233 lexicographically using ASCII ordering.
3234
3235'times'
3236 times
3237
3238 Print out the user and system times used by the shell and its
3239 children. The return status is zero.
3240
3241'trap'
3242 trap [-lp] [ARG] [SIGSPEC ...]
3243
3244 The commands in ARG are to be read and executed when the shell
3245 receives signal SIGSPEC. If ARG is absent (and there is a single
3246 SIGSPEC) or equal to '-', each specified signal's disposition is
3247 reset to the value it had when the shell was started. If ARG is
3248 the null string, then the signal specified by each SIGSPEC is
3249 ignored by the shell and commands it invokes. If ARG is not
3250 present and '-p' has been supplied, the shell displays the trap
3251 commands associated with each SIGSPEC. If no arguments are
3252 supplied, or only '-p' is given, 'trap' prints the list of commands
3253 associated with each signal number in a form that may be reused as
3254 shell input. The '-l' option causes the shell to print a list of
3255 signal names and their corresponding numbers. Each SIGSPEC is
3256 either a signal name or a signal number. Signal names are case
3257 insensitive and the 'SIG' prefix is optional.
3258
3259 If a SIGSPEC is '0' or 'EXIT', ARG is executed when the shell
3260 exits. If a SIGSPEC is 'DEBUG', the command ARG is executed before
3261 every simple command, 'for' command, 'case' command, 'select'
3262 command, every arithmetic 'for' command, and before the first
3263 command executes in a shell function. Refer to the description of
3264 the 'extdebug' option to the 'shopt' builtin (*note The Shopt
3265 Builtin::) for details of its effect on the 'DEBUG' trap. If a
3266 SIGSPEC is 'RETURN', the command ARG is executed each time a shell
3267 function or a script executed with the '.' or 'source' builtins
3268 finishes executing.
3269
3270 If a SIGSPEC is 'ERR', the command ARG is executed whenever a
3271 pipeline (which may consist of a single simple command), a list, or
3272 a compound command returns a non-zero exit status, subject to the
3273 following conditions. The 'ERR' trap is not executed if the failed
3274 command is part of the command list immediately following an
3275 'until' or 'while' keyword, part of the test following the 'if' or
3276 'elif' reserved words, part of a command executed in a '&&' or '||'
3277 list except the command following the final '&&' or '||', any
3278 command in a pipeline but the last, or if the command's return
3279 status is being inverted using '!'. These are the same conditions
3280 obeyed by the 'errexit' ('-e') option.
3281
3282 Signals ignored upon entry to the shell cannot be trapped or reset.
3283 Trapped signals that are not being ignored are reset to their
3284 original values in a subshell or subshell environment when one is
3285 created.
3286
3287 The return status is zero unless a SIGSPEC does not specify a valid
3288 signal.
3289
3290'umask'
3291 umask [-p] [-S] [MODE]
3292
3293 Set the shell process's file creation mask to MODE. If MODE begins
3294 with a digit, it is interpreted as an octal number; if not, it is
3295 interpreted as a symbolic mode mask similar to that accepted by the
3296 'chmod' command. If MODE is omitted, the current value of the mask
3297 is printed. If the '-S' option is supplied without a MODE
3298 argument, the mask is printed in a symbolic format. If the '-p'
3299 option is supplied, and MODE is omitted, the output is in a form
3300 that may be reused as input. The return status is zero if the mode
3301 is successfully changed or if no MODE argument is supplied, and
3302 non-zero otherwise.
3303
3304 Note that when the mode is interpreted as an octal number, each
3305 number of the umask is subtracted from '7'. Thus, a umask of '022'
3306 results in permissions of '755'.
3307
3308'unset'
3309 unset [-fnv] [NAME]
3310
3311 Remove each variable or function NAME. If the '-v' option is
3312 given, each NAME refers to a shell variable and that variable is
3313 removed. If the '-f' option is given, the NAMEs refer to shell
3314 functions, and the function definition is removed. If the '-n'
3315 option is supplied, and NAME is a variable with the NAMEREF
3316 attribute, NAME will be unset rather than the variable it
3317 references. '-n' has no effect if the '-f' option is supplied. If
3318 no options are supplied, each NAME refers to a variable; if there
3319 is no variable by that name, any function with that name is unset.
3320 Readonly variables and functions may not be unset. The return
3321 status is zero unless a NAME is readonly.
3322
3323\1f
3324File: bash.info, Node: Bash Builtins, Next: Modifying Shell Behavior, Prev: Bourne Shell Builtins, Up: Shell Builtin Commands
3325
33264.2 Bash Builtin Commands
3327=========================
3328
3329This section describes builtin commands which are unique to or have been
3330extended in Bash. Some of these commands are specified in the POSIX
3331standard.
3332
3333'alias'
3334 alias [-p] [NAME[=VALUE] ...]
3335
3336 Without arguments or with the '-p' option, 'alias' prints the list
3337 of aliases on the standard output in a form that allows them to be
3338 reused as input. If arguments are supplied, an alias is defined
3339 for each NAME whose VALUE is given. If no VALUE is given, the name
3340 and value of the alias is printed. Aliases are described in *note
3341 Aliases::.
3342
3343'bind'
3344 bind [-m KEYMAP] [-lpsvPSVX]
3345 bind [-m KEYMAP] [-q FUNCTION] [-u FUNCTION] [-r KEYSEQ]
3346 bind [-m KEYMAP] -f FILENAME
3347 bind [-m KEYMAP] -x KEYSEQ:SHELL-COMMAND
3348 bind [-m KEYMAP] KEYSEQ:FUNCTION-NAME
3349 bind [-m KEYMAP] KEYSEQ:READLINE-COMMAND
3350
3351 Display current Readline (*note Command Line Editing::) key and
3352 function bindings, bind a key sequence to a Readline function or
3353 macro, or set a Readline variable. Each non-option argument is a
3354 command as it would appear in a Readline initialization file (*note
3355 Readline Init File::), but each binding or command must be passed
3356 as a separate argument; e.g., '"\C-x\C-r":re-read-init-file'.
3357
3358 Options, if supplied, have the following meanings:
3359
3360 '-m KEYMAP'
3361 Use KEYMAP as the keymap to be affected by the subsequent
3362 bindings. Acceptable KEYMAP names are 'emacs',
3363 'emacs-standard', 'emacs-meta', 'emacs-ctlx', 'vi', 'vi-move',
3364 'vi-command', and 'vi-insert'. 'vi' is equivalent to
3365 'vi-command' ('vi-move' is also a synonym); 'emacs' is
3366 equivalent to 'emacs-standard'.
3367
3368 '-l'
3369 List the names of all Readline functions.
3370
3371 '-p'
3372 Display Readline function names and bindings in such a way
3373 that they can be used as input or in a Readline initialization
3374 file.
3375
3376 '-P'
3377 List current Readline function names and bindings.
3378
3379 '-v'
3380 Display Readline variable names and values in such a way that
3381 they can be used as input or in a Readline initialization
3382 file.
3383
3384 '-V'
3385 List current Readline variable names and values.
3386
3387 '-s'
3388 Display Readline key sequences bound to macros and the strings
3389 they output in such a way that they can be used as input or in
3390 a Readline initialization file.
3391
3392 '-S'
3393 Display Readline key sequences bound to macros and the strings
3394 they output.
3395
3396 '-f FILENAME'
3397 Read key bindings from FILENAME.
3398
3399 '-q FUNCTION'
3400 Query about which keys invoke the named FUNCTION.
3401
3402 '-u FUNCTION'
3403 Unbind all keys bound to the named FUNCTION.
3404
3405 '-r KEYSEQ'
3406 Remove any current binding for KEYSEQ.
3407
3408 '-x KEYSEQ:SHELL-COMMAND'
3409 Cause SHELL-COMMAND to be executed whenever KEYSEQ is entered.
3410 When SHELL-COMMAND is executed, the shell sets the
3411 'READLINE_LINE' variable to the contents of the Readline line
3412 buffer and the 'READLINE_POINT' variable to the current
3413 location of the insertion point. If the executed command
3414 changes the value of 'READLINE_LINE' or 'READLINE_POINT',
3415 those new values will be reflected in the editing state.
3416
3417 '-X'
3418 List all key sequences bound to shell commands and the
3419 associated commands in a format that can be reused as input.
3420
3421 The return status is zero unless an invalid option is supplied or
3422 an error occurs.
3423
3424'builtin'
3425 builtin [SHELL-BUILTIN [ARGS]]
3426
3427 Run a shell builtin, passing it ARGS, and return its exit status.
3428 This is useful when defining a shell function with the same name as
3429 a shell builtin, retaining the functionality of the builtin within
3430 the function. The return status is non-zero if SHELL-BUILTIN is
3431 not a shell builtin command.
3432
3433'caller'
3434 caller [EXPR]
3435
3436 Returns the context of any active subroutine call (a shell function
3437 or a script executed with the '.' or 'source' builtins).
3438
3439 Without EXPR, 'caller' displays the line number and source filename
3440 of the current subroutine call. If a non-negative integer is
3441 supplied as EXPR, 'caller' displays the line number, subroutine
3442 name, and source file corresponding to that position in the current
3443 execution call stack. This extra information may be used, for
3444 example, to print a stack trace. The current frame is frame 0.
3445
3446 The return value is 0 unless the shell is not executing a
3447 subroutine call or EXPR does not correspond to a valid position in
3448 the call stack.
3449
3450'command'
3451 command [-pVv] COMMAND [ARGUMENTS ...]
3452
3453 Runs COMMAND with ARGUMENTS ignoring any shell function named
3454 COMMAND. Only shell builtin commands or commands found by
3455 searching the 'PATH' are executed. If there is a shell function
3456 named 'ls', running 'command ls' within the function will execute
3457 the external command 'ls' instead of calling the function
3458 recursively. The '-p' option means to use a default value for
3459 'PATH' that is guaranteed to find all of the standard utilities.
3460 The return status in this case is 127 if COMMAND cannot be found or
3461 an error occurred, and the exit status of COMMAND otherwise.
3462
3463 If either the '-V' or '-v' option is supplied, a description of
3464 COMMAND is printed. The '-v' option causes a single word
3465 indicating the command or file name used to invoke COMMAND to be
3466 displayed; the '-V' option produces a more verbose description. In
3467 this case, the return status is zero if COMMAND is found, and
3468 non-zero if not.
3469
3470'declare'
3471 declare [-aAfFgilnrtux] [-p] [NAME[=VALUE] ...]
3472
3473 Declare variables and give them attributes. If no NAMEs are given,
3474 then display the values of variables instead.
3475
3476 The '-p' option will display the attributes and values of each
3477 NAME. When '-p' is used with NAME arguments, additional options,
3478 other than '-f' and '-F', are ignored.
3479
3480 When '-p' is supplied without NAME arguments, 'declare' will
3481 display the attributes and values of all variables having the
3482 attributes specified by the additional options. If no other
3483 options are supplied with '-p', 'declare' will display the
3484 attributes and values of all shell variables. The '-f' option will
3485 restrict the display to shell functions.
3486
3487 The '-F' option inhibits the display of function definitions; only
3488 the function name and attributes are printed. If the 'extdebug'
3489 shell option is enabled using 'shopt' (*note The Shopt Builtin::),
3490 the source file name and line number where each NAME is defined are
3491 displayed as well. '-F' implies '-f'.
3492
3493 The '-g' option forces variables to be created or modified at the
3494 global scope, even when 'declare' is executed in a shell function.
3495 It is ignored in all other cases.
3496
3497 The following options can be used to restrict output to variables
3498 with the specified attributes or to give variables attributes:
3499
3500 '-a'
3501 Each NAME is an indexed array variable (*note Arrays::).
3502
3503 '-A'
3504 Each NAME is an associative array variable (*note Arrays::).
3505
3506 '-f'
3507 Use function names only.
3508
3509 '-i'
3510 The variable is to be treated as an integer; arithmetic
3511 evaluation (*note Shell Arithmetic::) is performed when the
3512 variable is assigned a value.
3513
3514 '-l'
3515 When the variable is assigned a value, all upper-case
3516 characters are converted to lower-case. The upper-case
3517 attribute is disabled.
3518
3519 '-n'
3520 Give each NAME the NAMEREF attribute, making it a name
3521 reference to another variable. That other variable is defined
3522 by the value of NAME. All references, assignments, and
3523 attribute modifications to NAME, except for those using or
3524 changing the '-n' attribute itself, are performed on the
3525 variable referenced by NAME's value. The nameref attribute
3526 cannot be applied to array variables.
3527
3528 '-r'
3529 Make NAMEs readonly. These names cannot then be assigned
3530 values by subsequent assignment statements or unset.
3531
3532 '-t'
3533 Give each NAME the 'trace' attribute. Traced functions
3534 inherit the 'DEBUG' and 'RETURN' traps from the calling shell.
3535 The trace attribute has no special meaning for variables.
3536
3537 '-u'
3538 When the variable is assigned a value, all lower-case
3539 characters are converted to upper-case. The lower-case
3540 attribute is disabled.
3541
3542 '-x'
3543 Mark each NAME for export to subsequent commands via the
3544 environment.
3545
3546 Using '+' instead of '-' turns off the attribute instead, with the
d233b485
CR
3547 exceptions that '+a' and '+A' may not be used to destroy array
3548 variables and '+r' will not remove the readonly attribute. When
3549 used in a function, 'declare' makes each NAME local, as with the
3550 'local' command, unless the '-g' option is used. If a variable
3551 name is followed by =VALUE, the value of the variable is set to
3552 VALUE.
a0c0a00f
CR
3553
3554 When using '-a' or '-A' and the compound assignment syntax to
3555 create array variables, additional attributes do not take effect
3556 until subsequent assignments.
3557
3558 The return status is zero unless an invalid option is encountered,
3559 an attempt is made to define a function using '-f foo=bar', an
3560 attempt is made to assign a value to a readonly variable, an
3561 attempt is made to assign a value to an array variable without
3562 using the compound assignment syntax (*note Arrays::), one of the
3563 NAMES is not a valid shell variable name, an attempt is made to
3564 turn off readonly status for a readonly variable, an attempt is
3565 made to turn off array status for an array variable, or an attempt
3566 is made to display a non-existent function with '-f'.
3567
3568'echo'
3569 echo [-neE] [ARG ...]
3570
3571 Output the ARGs, separated by spaces, terminated with a newline.
3572 The return status is 0 unless a write error occurs. If '-n' is
3573 specified, the trailing newline is suppressed. If the '-e' option
3574 is given, interpretation of the following backslash-escaped
3575 characters is enabled. The '-E' option disables the interpretation
3576 of these escape characters, even on systems where they are
3577 interpreted by default. The 'xpg_echo' shell option may be used to
3578 dynamically determine whether or not 'echo' expands these escape
3579 characters by default. 'echo' does not interpret '--' to mean the
3580 end of options.
3581
3582 'echo' interprets the following escape sequences:
3583 '\a'
3584 alert (bell)
3585 '\b'
3586 backspace
3587 '\c'
3588 suppress further output
3589 '\e'
3590 '\E'
3591 escape
3592 '\f'
3593 form feed
3594 '\n'
3595 new line
3596 '\r'
3597 carriage return
3598 '\t'
3599 horizontal tab
3600 '\v'
3601 vertical tab
3602 '\\'
3603 backslash
3604 '\0NNN'
3605 the eight-bit character whose value is the octal value NNN
3606 (zero to three octal digits)
3607 '\xHH'
3608 the eight-bit character whose value is the hexadecimal value
3609 HH (one or two hex digits)
3610 '\uHHHH'
3611 the Unicode (ISO/IEC 10646) character whose value is the
3612 hexadecimal value HHHH (one to four hex digits)
3613 '\UHHHHHHHH'
3614 the Unicode (ISO/IEC 10646) character whose value is the
3615 hexadecimal value HHHHHHHH (one to eight hex digits)
3616
3617'enable'
3618 enable [-a] [-dnps] [-f FILENAME] [NAME ...]
3619
3620 Enable and disable builtin shell commands. Disabling a builtin
3621 allows a disk command which has the same name as a shell builtin to
3622 be executed without specifying a full pathname, even though the
3623 shell normally searches for builtins before disk commands. If '-n'
3624 is used, the NAMEs become disabled. Otherwise NAMEs are enabled.
3625 For example, to use the 'test' binary found via '$PATH' instead of
3626 the shell builtin version, type 'enable -n test'.
3627
3628 If the '-p' option is supplied, or no NAME arguments appear, a list
3629 of shell builtins is printed. With no other arguments, the list
3630 consists of all enabled shell builtins. The '-a' option means to
3631 list each builtin with an indication of whether or not it is
3632 enabled.
3633
3634 The '-f' option means to load the new builtin command NAME from
3635 shared object FILENAME, on systems that support dynamic loading.
3636 The '-d' option will delete a builtin loaded with '-f'.
3637
3638 If there are no options, a list of the shell builtins is displayed.
3639 The '-s' option restricts 'enable' to the POSIX special builtins.
3640 If '-s' is used with '-f', the new builtin becomes a special
3641 builtin (*note Special Builtins::).
3642
3643 The return status is zero unless a NAME is not a shell builtin or
3644 there is an error loading a new builtin from a shared object.
3645
3646'help'
3647 help [-dms] [PATTERN]
3648
3649 Display helpful information about builtin commands. If PATTERN is
3650 specified, 'help' gives detailed help on all commands matching
3651 PATTERN, otherwise a list of the builtins is printed.
3652
3653 Options, if supplied, have the following meanings:
3654
3655 '-d'
3656 Display a short description of each PATTERN
3657 '-m'
3658 Display the description of each PATTERN in a manpage-like
3659 format
3660 '-s'
3661 Display only a short usage synopsis for each PATTERN
3662
3663 The return status is zero unless no command matches PATTERN.
3664
3665'let'
3666 let EXPRESSION [EXPRESSION ...]
3667
3668 The 'let' builtin allows arithmetic to be performed on shell
3669 variables. Each EXPRESSION is evaluated according to the rules
3670 given below in *note Shell Arithmetic::. If the last EXPRESSION
3671 evaluates to 0, 'let' returns 1; otherwise 0 is returned.
3672
3673'local'
3674 local [OPTION] NAME[=VALUE] ...
3675
3676 For each argument, a local variable named NAME is created, and
3677 assigned VALUE. The OPTION can be any of the options accepted by
3678 'declare'. 'local' can only be used within a function; it makes
3679 the variable NAME have a visible scope restricted to that function
3680 and its children. If NAME is '-', the set of shell options is made
3681 local to the function in which 'local' is invoked: shell options
3682 changed using the 'set' builtin inside the function are restored to
3683 their original values when the function returns. The return status
3684 is zero unless 'local' is used outside a function, an invalid NAME
3685 is supplied, or NAME is a readonly variable.
3686
3687'logout'
3688 logout [N]
3689
3690 Exit a login shell, returning a status of N to the shell's parent.
3691
3692'mapfile'
d233b485
CR
3693 mapfile [-d DELIM] [-n COUNT] [-O ORIGIN] [-s COUNT]
3694 [-t] [-u FD] [-C CALLBACK] [-c QUANTUM] [ARRAY]
a0c0a00f
CR
3695
3696 Read lines from the standard input into the indexed array variable
3697 ARRAY, or from file descriptor FD if the '-u' option is supplied.
3698 The variable 'MAPFILE' is the default ARRAY. Options, if supplied,
3699 have the following meanings:
3700
3701 '-d'
3702 The first character of DELIM is used to terminate each input
d233b485
CR
3703 line, rather than newline. If DELIM is the empty string,
3704 'mapfile' will terminate a line when it reads a NUL character.
a0c0a00f
CR
3705 '-n'
3706 Copy at most COUNT lines. If COUNT is 0, all lines are
3707 copied.
3708 '-O'
3709 Begin assigning to ARRAY at index ORIGIN. The default index
3710 is 0.
3711 '-s'
3712 Discard the first COUNT lines read.
3713 '-t'
3714 Remove a trailing DELIM (default newline) from each line read.
3715 '-u'
3716 Read lines from file descriptor FD instead of the standard
3717 input.
3718 '-C'
d233b485 3719 Evaluate CALLBACK each time QUANTUM lines are read. The '-c'
a0c0a00f
CR
3720 option specifies QUANTUM.
3721 '-c'
3722 Specify the number of lines read between each call to
3723 CALLBACK.
3724
3725 If '-C' is specified without '-c', the default quantum is 5000.
3726 When CALLBACK is evaluated, it is supplied the index of the next
3727 array element to be assigned and the line to be assigned to that
3728 element as additional arguments. CALLBACK is evaluated after the
3729 line is read but before the array element is assigned.
3730
3731 If not supplied with an explicit origin, 'mapfile' will clear ARRAY
3732 before assigning to it.
3733
3734 'mapfile' returns successfully unless an invalid option or option
3735 argument is supplied, ARRAY is invalid or unassignable, or ARRAY is
3736 not an indexed array.
3737
3738'printf'
3739 printf [-v VAR] FORMAT [ARGUMENTS]
3740
3741 Write the formatted ARGUMENTS to the standard output under the
3742 control of the FORMAT. The '-v' option causes the output to be
3743 assigned to the variable VAR rather than being printed to the
3744 standard output.
3745
3746 The FORMAT is a character string which contains three types of
3747 objects: plain characters, which are simply copied to standard
3748 output, character escape sequences, which are converted and copied
3749 to the standard output, and format specifications, each of which
3750 causes printing of the next successive ARGUMENT. In addition to
3751 the standard 'printf(1)' formats, 'printf' interprets the following
3752 extensions:
3753
3754 '%b'
3755 Causes 'printf' to expand backslash escape sequences in the
3756 corresponding ARGUMENT in the same way as 'echo -e' (*note
3757 Bash Builtins::).
3758 '%q'
3759 Causes 'printf' to output the corresponding ARGUMENT in a
3760 format that can be reused as shell input.
3761 '%(DATEFMT)T'
3762 Causes 'printf' to output the date-time string resulting from
3763 using DATEFMT as a format string for 'strftime'(3). The
3764 corresponding ARGUMENT is an integer representing the number
3765 of seconds since the epoch. Two special argument values may
3766 be used: -1 represents the current time, and -2 represents the
3767 time the shell was invoked. If no argument is specified,
3768 conversion behaves as if -1 had been given. This is an
3769 exception to the usual 'printf' behavior.
3770
3771 Arguments to non-string format specifiers are treated as C language
3772 constants, except that a leading plus or minus sign is allowed, and
3773 if the leading character is a single or double quote, the value is
3774 the ASCII value of the following character.
3775
3776 The FORMAT is reused as necessary to consume all of the ARGUMENTS.
3777 If the FORMAT requires more ARGUMENTS than are supplied, the extra
3778 format specifications behave as if a zero value or null string, as
3779 appropriate, had been supplied. The return value is zero on
3780 success, non-zero on failure.
3781
3782'read'
3783 read [-ers] [-a ANAME] [-d DELIM] [-i TEXT] [-n NCHARS]
3784 [-N NCHARS] [-p PROMPT] [-t TIMEOUT] [-u FD] [NAME ...]
3785
3786 One line is read from the standard input, or from the file
3787 descriptor FD supplied as an argument to the '-u' option, split
3788 into words as described above in *note Word Splitting::, and the
3789 first word is assigned to the first NAME, the second word to the
3790 second NAME, and so on. If there are more words than names, the
3791 remaining words and their intervening delimiters are assigned to
3792 the last NAME. If there are fewer words read from the input stream
3793 than names, the remaining names are assigned empty values. The
3794 characters in the value of the 'IFS' variable are used to split the
3795 line into words using the same rules the shell uses for expansion
3796 (described above in *note Word Splitting::). The backslash
3797 character '\' may be used to remove any special meaning for the
3798 next character read and for line continuation. If no names are
3799 supplied, the line read is assigned to the variable 'REPLY'. The
3800 exit status is zero, unless end-of-file is encountered, 'read'
3801 times out (in which case the status is greater than 128), a
3802 variable assignment error (such as assigning to a readonly
3803 variable) occurs, or an invalid file descriptor is supplied as the
3804 argument to '-u'.
3805
3806 Options, if supplied, have the following meanings:
3807
3808 '-a ANAME'
3809 The words are assigned to sequential indices of the array
3810 variable ANAME, starting at 0. All elements are removed from
3811 ANAME before the assignment. Other NAME arguments are
3812 ignored.
3813
3814 '-d DELIM'
3815 The first character of DELIM is used to terminate the input
d233b485
CR
3816 line, rather than newline. If DELIM is the empty string,
3817 'read' will terminate a line when it reads a NUL character.
a0c0a00f
CR
3818
3819 '-e'
3820 Readline (*note Command Line Editing::) is used to obtain the
3821 line. Readline uses the current (or default, if line editing
d233b485
CR
3822 was not previously active) editing settings, but uses
3823 Readline's default filename completion.
a0c0a00f
CR
3824
3825 '-i TEXT'
3826 If Readline is being used to read the line, TEXT is placed
3827 into the editing buffer before editing begins.
3828
3829 '-n NCHARS'
3830 'read' returns after reading NCHARS characters rather than
3831 waiting for a complete line of input, but honors a delimiter
3832 if fewer than NCHARS characters are read before the delimiter.
3833
3834 '-N NCHARS'
3835 'read' returns after reading exactly NCHARS characters rather
3836 than waiting for a complete line of input, unless EOF is
3837 encountered or 'read' times out. Delimiter characters
3838 encountered in the input are not treated specially and do not
3839 cause 'read' to return until NCHARS characters are read. The
3840 result is not split on the characters in 'IFS'; the intent is
3841 that the variable is assigned exactly the characters read
3842 (with the exception of backslash; see the '-r' option below).
3843
3844 '-p PROMPT'
3845 Display PROMPT, without a trailing newline, before attempting
3846 to read any input. The prompt is displayed only if input is
3847 coming from a terminal.
3848
3849 '-r'
3850 If this option is given, backslash does not act as an escape
3851 character. The backslash is considered to be part of the
d233b485
CR
3852 line. In particular, a backslash-newline pair may not then be
3853 used as a line continuation.
a0c0a00f
CR
3854
3855 '-s'
3856 Silent mode. If input is coming from a terminal, characters
3857 are not echoed.
3858
3859 '-t TIMEOUT'
3860 Cause 'read' to time out and return failure if a complete line
3861 of input (or a specified number of characters) is not read
3862 within TIMEOUT seconds. TIMEOUT may be a decimal number with
3863 a fractional portion following the decimal point. This option
3864 is only effective if 'read' is reading input from a terminal,
3865 pipe, or other special file; it has no effect when reading
3866 from regular files. If 'read' times out, 'read' saves any
3867 partial input read into the specified variable NAME. If
3868 TIMEOUT is 0, 'read' returns immediately, without trying to
3869 read and data. The exit status is 0 if input is available on
3870 the specified file descriptor, non-zero otherwise. The exit
3871 status is greater than 128 if the timeout is exceeded.
3872
3873 '-u FD'
3874 Read input from file descriptor FD.
3875
3876'readarray'
d233b485
CR
3877 readarray [-d DELIM] [-n COUNT] [-O ORIGIN] [-s COUNT]
3878 [-t] [-u FD] [-C CALLBACK] [-c QUANTUM] [ARRAY]
a0c0a00f
CR
3879
3880 Read lines from the standard input into the indexed array variable
3881 ARRAY, or from file descriptor FD if the '-u' option is supplied.
3882
3883 A synonym for 'mapfile'.
3884
3885'source'
3886 source FILENAME
3887
3888 A synonym for '.' (*note Bourne Shell Builtins::).
3889
3890'type'
3891 type [-afptP] [NAME ...]
3892
3893 For each NAME, indicate how it would be interpreted if used as a
3894 command name.
3895
3896 If the '-t' option is used, 'type' prints a single word which is
3897 one of 'alias', 'function', 'builtin', 'file' or 'keyword', if NAME
3898 is an alias, shell function, shell builtin, disk file, or shell
3899 reserved word, respectively. If the NAME is not found, then
3900 nothing is printed, and 'type' returns a failure status.
3901
3902 If the '-p' option is used, 'type' either returns the name of the
3903 disk file that would be executed, or nothing if '-t' would not
3904 return 'file'.
3905
3906 The '-P' option forces a path search for each NAME, even if '-t'
3907 would not return 'file'.
3908
3909 If a command is hashed, '-p' and '-P' print the hashed value, which
3910 is not necessarily the file that appears first in '$PATH'.
3911
3912 If the '-a' option is used, 'type' returns all of the places that
3913 contain an executable named FILE. This includes aliases and
3914 functions, if and only if the '-p' option is not also used.
3915
3916 If the '-f' option is used, 'type' does not attempt to find shell
3917 functions, as with the 'command' builtin.
3918
3919 The return status is zero if all of the NAMES are found, non-zero
3920 if any are not found.
3921
3922'typeset'
3923 typeset [-afFgrxilnrtux] [-p] [NAME[=VALUE] ...]
3924
3925 The 'typeset' command is supplied for compatibility with the Korn
3926 shell. It is a synonym for the 'declare' builtin command.
3927
3928'ulimit'
3929 ulimit [-HSabcdefiklmnpqrstuvxPT] [LIMIT]
3930
3931 'ulimit' provides control over the resources available to processes
3932 started by the shell, on systems that allow such control. If an
3933 option is given, it is interpreted as follows:
3934
3935 '-S'
3936 Change and report the soft limit associated with a resource.
3937
3938 '-H'
3939 Change and report the hard limit associated with a resource.
3940
3941 '-a'
3942 All current limits are reported.
3943
3944 '-b'
3945 The maximum socket buffer size.
3946
3947 '-c'
3948 The maximum size of core files created.
3949
3950 '-d'
3951 The maximum size of a process's data segment.
3952
3953 '-e'
3954 The maximum scheduling priority ("nice").
3955
3956 '-f'
3957 The maximum size of files written by the shell and its
3958 children.
3959
3960 '-i'
3961 The maximum number of pending signals.
3962
3963 '-k'
3964 The maximum number of kqueues that may be allocated.
3965
3966 '-l'
3967 The maximum size that may be locked into memory.
3968
3969 '-m'
3970 The maximum resident set size (many systems do not honor this
3971 limit).
3972
3973 '-n'
3974 The maximum number of open file descriptors (most systems do
3975 not allow this value to be set).
3976
3977 '-p'
3978 The pipe buffer size.
3979
3980 '-q'
3981 The maximum number of bytes in POSIX message queues.
3982
3983 '-r'
3984 The maximum real-time scheduling priority.
3985
3986 '-s'
3987 The maximum stack size.
3988
3989 '-t'
3990 The maximum amount of cpu time in seconds.
3991
3992 '-u'
3993 The maximum number of processes available to a single user.
3994
3995 '-v'
3996 The maximum amount of virtual memory available to the shell,
3997 and, on some systems, to its children.
3998
3999 '-x'
4000 The maximum number of file locks.
4001
4002 '-P'
4003 The maximum number of pseudoterminals.
4004
4005 '-T'
4006 The maximum number of threads.
4007
4008 If LIMIT is given, and the '-a' option is not used, LIMIT is the
4009 new value of the specified resource. The special LIMIT values
4010 'hard', 'soft', and 'unlimited' stand for the current hard limit,
4011 the current soft limit, and no limit, respectively. A hard limit
4012 cannot be increased by a non-root user once it is set; a soft limit
4013 may be increased up to the value of the hard limit. Otherwise, the
4014 current value of the soft limit for the specified resource is
4015 printed, unless the '-H' option is supplied. When setting new
4016 limits, if neither '-H' nor '-S' is supplied, both the hard and
4017 soft limits are set. If no option is given, then '-f' is assumed.
4018 Values are in 1024-byte increments, except for '-t', which is in
4019 seconds; '-p', which is in units of 512-byte blocks; '-P', '-T',
4020 '-b', '-k', '-n' and '-u', which are unscaled values; and, when in
4021 POSIX Mode (*note Bash POSIX Mode::), '-c' and '-f', which are in
4022 512-byte increments.
4023
4024 The return status is zero unless an invalid option or argument is
4025 supplied, or an error occurs while setting a new limit.
4026
4027'unalias'
4028 unalias [-a] [NAME ... ]
4029
4030 Remove each NAME from the list of aliases. If '-a' is supplied,
4031 all aliases are removed. Aliases are described in *note Aliases::.
4032
4033\1f
4034File: bash.info, Node: Modifying Shell Behavior, Next: Special Builtins, Prev: Bash Builtins, Up: Shell Builtin Commands
4035
40364.3 Modifying Shell Behavior
4037============================
4038
4039* Menu:
4040
4041* The Set Builtin:: Change the values of shell attributes and
4042 positional parameters.
4043* The Shopt Builtin:: Modify shell optional behavior.
4044
4045\1f
4046File: bash.info, Node: The Set Builtin, Next: The Shopt Builtin, Up: Modifying Shell Behavior
4047
40484.3.1 The Set Builtin
4049---------------------
4050
4051This builtin is so complicated that it deserves its own section. 'set'
4052allows you to change the values of shell options and set the positional
4053parameters, or to display the names and values of shell variables.
4054
4055'set'
4056 set [--abefhkmnptuvxBCEHPT] [-o OPTION-NAME] [ARGUMENT ...]
4057 set [+abefhkmnptuvxBCEHPT] [+o OPTION-NAME] [ARGUMENT ...]
4058
4059 If no options or arguments are supplied, 'set' displays the names
4060 and values of all shell variables and functions, sorted according
4061 to the current locale, in a format that may be reused as input for
4062 setting or resetting the currently-set variables. Read-only
4063 variables cannot be reset. In POSIX mode, only shell variables are
4064 listed.
4065
4066 When options are supplied, they set or unset shell attributes.
4067 Options, if specified, have the following meanings:
4068
4069 '-a'
4070 Each variable or function that is created or modified is given
4071 the export attribute and marked for export to the environment
4072 of subsequent commands.
4073
4074 '-b'
4075 Cause the status of terminated background jobs to be reported
4076 immediately, rather than before printing the next primary
4077 prompt.
4078
4079 '-e'
4080 Exit immediately if a pipeline (*note Pipelines::), which may
4081 consist of a single simple command (*note Simple Commands::),
4082 a list (*note Lists::), or a compound command (*note Compound
4083 Commands::) returns a non-zero status. The shell does not
4084 exit if the command that fails is part of the command list
4085 immediately following a 'while' or 'until' keyword, part of
4086 the test in an 'if' statement, part of any command executed in
4087 a '&&' or '||' list except the command following the final
4088 '&&' or '||', any command in a pipeline but the last, or if
4089 the command's return status is being inverted with '!'. If a
4090 compound command other than a subshell returns a non-zero
4091 status because a command failed while '-e' was being ignored,
4092 the shell does not exit. A trap on 'ERR', if set, is executed
4093 before the shell exits.
4094
4095 This option applies to the shell environment and each subshell
4096 environment separately (*note Command Execution
4097 Environment::), and may cause subshells to exit before
4098 executing all the commands in the subshell.
4099
4100 If a compound command or shell function executes in a context
4101 where '-e' is being ignored, none of the commands executed
4102 within the compound command or function body will be affected
4103 by the '-e' setting, even if '-e' is set and a command returns
4104 a failure status. If a compound command or shell function
4105 sets '-e' while executing in a context where '-e' is ignored,
4106 that setting will not have any effect until the compound
4107 command or the command containing the function call completes.
4108
4109 '-f'
4110 Disable filename expansion (globbing).
4111
4112 '-h'
4113 Locate and remember (hash) commands as they are looked up for
4114 execution. This option is enabled by default.
4115
4116 '-k'
4117 All arguments in the form of assignment statements are placed
4118 in the environment for a command, not just those that precede
4119 the command name.
4120
4121 '-m'
4122 Job control is enabled (*note Job Control::). All processes
4123 run in a separate process group. When a background job
4124 completes, the shell prints a line containing its exit status.
4125
4126 '-n'
4127 Read commands but do not execute them. This may be used to
4128 check a script for syntax errors. This option is ignored by
4129 interactive shells.
4130
4131 '-o OPTION-NAME'
4132
4133 Set the option corresponding to OPTION-NAME:
4134
4135 'allexport'
4136 Same as '-a'.
4137
4138 'braceexpand'
4139 Same as '-B'.
4140
4141 'emacs'
4142 Use an 'emacs'-style line editing interface (*note
4143 Command Line Editing::). This also affects the editing
4144 interface used for 'read -e'.
4145
4146 'errexit'
4147 Same as '-e'.
4148
4149 'errtrace'
4150 Same as '-E'.
4151
4152 'functrace'
4153 Same as '-T'.
4154
4155 'hashall'
4156 Same as '-h'.
4157
4158 'histexpand'
4159 Same as '-H'.
4160
4161 'history'
4162 Enable command history, as described in *note Bash
4163 History Facilities::. This option is on by default in
4164 interactive shells.
4165
4166 'ignoreeof'
4167 An interactive shell will not exit upon reading EOF.
4168
4169 'keyword'
4170 Same as '-k'.
4171
4172 'monitor'
4173 Same as '-m'.
4174
4175 'noclobber'
4176 Same as '-C'.
4177
4178 'noexec'
4179 Same as '-n'.
4180
4181 'noglob'
4182 Same as '-f'.
4183
4184 'nolog'
4185 Currently ignored.
4186
4187 'notify'
4188 Same as '-b'.
4189
4190 'nounset'
4191 Same as '-u'.
4192
4193 'onecmd'
4194 Same as '-t'.
4195
4196 'physical'
4197 Same as '-P'.
4198
4199 'pipefail'
4200 If set, the return value of a pipeline is the value of
4201 the last (rightmost) command to exit with a non-zero
4202 status, or zero if all commands in the pipeline exit
4203 successfully. This option is disabled by default.
4204
4205 'posix'
4206 Change the behavior of Bash where the default operation
4207 differs from the POSIX standard to match the standard
4208 (*note Bash POSIX Mode::). This is intended to make Bash
4209 behave as a strict superset of that standard.
4210
4211 'privileged'
4212 Same as '-p'.
4213
4214 'verbose'
4215 Same as '-v'.
4216
4217 'vi'
4218 Use a 'vi'-style line editing interface. This also
4219 affects the editing interface used for 'read -e'.
4220
4221 'xtrace'
4222 Same as '-x'.
4223
4224 '-p'
4225 Turn on privileged mode. In this mode, the '$BASH_ENV' and
4226 '$ENV' files are not processed, shell functions are not
4227 inherited from the environment, and the 'SHELLOPTS',
4228 'BASHOPTS', 'CDPATH' and 'GLOBIGNORE' variables, if they
4229 appear in the environment, are ignored. If the shell is
4230 started with the effective user (group) id not equal to the
4231 real user (group) id, and the '-p' option is not supplied,
4232 these actions are taken and the effective user id is set to
4233 the real user id. If the '-p' option is supplied at startup,
4234 the effective user id is not reset. Turning this option off
4235 causes the effective user and group ids to be set to the real
4236 user and group ids.
4237
4238 '-t'
4239 Exit after reading and executing one command.
4240
4241 '-u'
4242 Treat unset variables and parameters other than the special
4243 parameters '@' or '*' as an error when performing parameter
4244 expansion. An error message will be written to the standard
4245 error, and a non-interactive shell will exit.
4246
4247 '-v'
4248 Print shell input lines as they are read.
4249
4250 '-x'
4251 Print a trace of simple commands, 'for' commands, 'case'
4252 commands, 'select' commands, and arithmetic 'for' commands and
4253 their arguments or associated word lists after they are
4254 expanded and before they are executed. The value of the 'PS4'
4255 variable is expanded and the resultant value is printed before
4256 the command and its expanded arguments.
4257
4258 '-B'
4259 The shell will perform brace expansion (*note Brace
4260 Expansion::). This option is on by default.
4261
4262 '-C'
4263 Prevent output redirection using '>', '>&', and '<>' from
4264 overwriting existing files.
4265
4266 '-E'
4267 If set, any trap on 'ERR' is inherited by shell functions,
4268 command substitutions, and commands executed in a subshell
4269 environment. The 'ERR' trap is normally not inherited in such
4270 cases.
4271
4272 '-H'
4273 Enable '!' style history substitution (*note History
4274 Interaction::). This option is on by default for interactive
4275 shells.
4276
4277 '-P'
4278 If set, do not resolve symbolic links when performing commands
4279 such as 'cd' which change the current directory. The physical
4280 directory is used instead. By default, Bash follows the
4281 logical chain of directories when performing commands which
4282 change the current directory.
4283
4284 For example, if '/usr/sys' is a symbolic link to
4285 '/usr/local/sys' then:
4286 $ cd /usr/sys; echo $PWD
4287 /usr/sys
4288 $ cd ..; pwd
4289 /usr
4290
4291 If 'set -P' is on, then:
4292 $ cd /usr/sys; echo $PWD
4293 /usr/local/sys
4294 $ cd ..; pwd
4295 /usr/local
4296
4297 '-T'
4298 If set, any trap on 'DEBUG' and 'RETURN' are inherited by
4299 shell functions, command substitutions, and commands executed
4300 in a subshell environment. The 'DEBUG' and 'RETURN' traps are
4301 normally not inherited in such cases.
4302
4303 '--'
4304 If no arguments follow this option, then the positional
4305 parameters are unset. Otherwise, the positional parameters
4306 are set to the ARGUMENTS, even if some of them begin with a
4307 '-'.
4308
4309 '-'
4310 Signal the end of options, cause all remaining ARGUMENTS to be
4311 assigned to the positional parameters. The '-x' and '-v'
4312 options are turned off. If there are no arguments, the
4313 positional parameters remain unchanged.
4314
4315 Using '+' rather than '-' causes these options to be turned off.
4316 The options can also be used upon invocation of the shell. The
4317 current set of options may be found in '$-'.
4318
4319 The remaining N ARGUMENTS are positional parameters and are
4320 assigned, in order, to '$1', '$2', ... '$N'. The special parameter
4321 '#' is set to N.
4322
4323 The return status is always zero unless an invalid option is
4324 supplied.
4325
4326\1f
4327File: bash.info, Node: The Shopt Builtin, Prev: The Set Builtin, Up: Modifying Shell Behavior
4328
43294.3.2 The Shopt Builtin
4330-----------------------
4331
4332This builtin allows you to change additional shell optional behavior.
4333
4334'shopt'
4335 shopt [-pqsu] [-o] [OPTNAME ...]
4336
4337 Toggle the values of settings controlling optional shell behavior.
4338 The settings can be either those listed below, or, if the '-o'
4339 option is used, those available with the '-o' option to the 'set'
4340 builtin command (*note The Set Builtin::). With no options, or
4341 with the '-p' option, a list of all settable options is displayed,
d233b485
CR
4342 with an indication of whether or not each is set; if OPTNAMES are
4343 supplied, the output is restricted to those options. The '-p'
4344 option causes output to be displayed in a form that may be reused
4345 as input. Other options have the following meanings:
a0c0a00f
CR
4346
4347 '-s'
4348 Enable (set) each OPTNAME.
4349
4350 '-u'
4351 Disable (unset) each OPTNAME.
4352
4353 '-q'
4354 Suppresses normal output; the return status indicates whether
4355 the OPTNAME is set or unset. If multiple OPTNAME arguments
4356 are given with '-q', the return status is zero if all OPTNAMES
4357 are enabled; non-zero otherwise.
4358
4359 '-o'
4360 Restricts the values of OPTNAME to be those defined for the
4361 '-o' option to the 'set' builtin (*note The Set Builtin::).
4362
4363 If either '-s' or '-u' is used with no OPTNAME arguments, 'shopt'
4364 shows only those options which are set or unset, respectively.
4365
4366 Unless otherwise noted, the 'shopt' options are disabled (off) by
4367 default.
4368
4369 The return status when listing options is zero if all OPTNAMES are
4370 enabled, non-zero otherwise. When setting or unsetting options,
4371 the return status is zero unless an OPTNAME is not a valid shell
4372 option.
4373
4374 The list of 'shopt' options is:
4375
d233b485
CR
4376 'assoc_expand_once'
4377 If set, the shell suppresses multiple evaluation of
4378 associative array subscripts during arithmetic expression
4379 evaluation, while executing builtins that can perform variable
4380 assignments, and while executing builtins that perform array
4381 dereferencing.
4382
a0c0a00f
CR
4383 'autocd'
4384 If set, a command name that is the name of a directory is
4385 executed as if it were the argument to the 'cd' command. This
4386 option is only used by interactive shells.
4387
4388 'cdable_vars'
4389 If this is set, an argument to the 'cd' builtin command that
4390 is not a directory is assumed to be the name of a variable
4391 whose value is the directory to change to.
4392
4393 'cdspell'
4394 If set, minor errors in the spelling of a directory component
4395 in a 'cd' command will be corrected. The errors checked for
4396 are transposed characters, a missing character, and a
4397 character too many. If a correction is found, the corrected
4398 path is printed, and the command proceeds. This option is
4399 only used by interactive shells.
4400
4401 'checkhash'
4402 If this is set, Bash checks that a command found in the hash
4403 table exists before trying to execute it. If a hashed command
4404 no longer exists, a normal path search is performed.
4405
4406 'checkjobs'
4407 If set, Bash lists the status of any stopped and running jobs
4408 before exiting an interactive shell. If any jobs are running,
4409 this causes the exit to be deferred until a second exit is
4410 attempted without an intervening command (*note Job
4411 Control::). The shell always postpones exiting if any jobs
4412 are stopped.
4413
4414 'checkwinsize'
d233b485
CR
4415 If set, Bash checks the window size after each external
4416 (non-builtin) command and, if necessary, updates the values of
4417 'LINES' and 'COLUMNS'. This option is enabled by default.
a0c0a00f
CR
4418
4419 'cmdhist'
4420 If set, Bash attempts to save all lines of a multiple-line
4421 command in the same history entry. This allows easy
d233b485
CR
4422 re-editing of multi-line commands. This option is enabled by
4423 default, but only has an effect if command history is enabled
4424 (*note Bash History Facilities::).
a0c0a00f
CR
4425
4426 'compat31'
4427 If set, Bash changes its behavior to that of version 3.1 with
4428 respect to quoted arguments to the conditional command's '=~'
4429 operator and with respect to locale-specific string comparison
4430 when using the '[[' conditional command's '<' and '>'
4431 operators. Bash versions prior to bash-4.1 use ASCII
4432 collation and strcmp(3); bash-4.1 and later use the current
4433 locale's collation sequence and strcoll(3).
4434
4435 'compat32'
4436 If set, Bash changes its behavior to that of version 3.2 with
4437 respect to locale-specific string comparison when using the
4438 '[[' conditional command's '<' and '>' operators (see previous
4439 item) and the effect of interrupting a command list. Bash
4440 versions 3.2 and earlier continue with the next command in the
4441 list after one terminates due to an interrupt.
4442
4443 'compat40'
4444 If set, Bash changes its behavior to that of version 4.0 with
4445 respect to locale-specific string comparison when using the
4446 '[[' conditional command's '<' and '>' operators (see
4447 description of 'compat31') and the effect of interrupting a
4448 command list. Bash versions 4.0 and later interrupt the list
4449 as if the shell received the interrupt; previous versions
4450 continue with the next command in the list.
4451
4452 'compat41'
4453 If set, Bash, when in POSIX mode, treats a single quote in a
4454 double-quoted parameter expansion as a special character. The
4455 single quotes must match (an even number) and the characters
4456 between the single quotes are considered quoted. This is the
4457 behavior of POSIX mode through version 4.1. The default Bash
4458 behavior remains as in previous versions.
4459
4460 'compat42'
4461 If set, Bash does not process the replacement string in the
4462 pattern substitution word expansion using quote removal.
4463
4464 'compat43'
4465 If set, Bash does not print a warning message if an attempt is
4466 made to use a quoted compound array assignment as an argument
4467 to 'declare', makes word expansion errors non-fatal errors
4468 that cause the current command to fail (the default behavior
4469 is to make them fatal errors that cause the shell to exit),
4470 and does not reset the loop state when a shell function is
4471 executed (this allows 'break' or 'continue' in a shell
4472 function to affect loops in the caller's context).
4473
d233b485
CR
4474 'compat44'
4475 If set, Bash saves the positional parameters to BASH_ARGV and
4476 BASH_ARGC before they are used, regardless of whether or not
4477 extended debugging mode is enabled.
4478
a0c0a00f
CR
4479 'complete_fullquote'
4480 If set, Bash quotes all shell metacharacters in filenames and
4481 directory names when performing completion. If not set, Bash
4482 removes metacharacters such as the dollar sign from the set of
4483 characters that will be quoted in completed filenames when
4484 these metacharacters appear in shell variable references in
4485 words to be completed. This means that dollar signs in
4486 variable names that expand to directories will not be quoted;
4487 however, any dollar signs appearing in filenames will not be
4488 quoted, either. This is active only when bash is using
4489 backslashes to quote completed filenames. This variable is
4490 set by default, which is the default Bash behavior in versions
4491 through 4.2.
4492
4493 'direxpand'
4494 If set, Bash replaces directory names with the results of word
4495 expansion when performing filename completion. This changes
4496 the contents of the readline editing buffer. If not set, Bash
4497 attempts to preserve what the user typed.
4498
4499 'dirspell'
4500 If set, Bash attempts spelling correction on directory names
4501 during word completion if the directory name initially
4502 supplied does not exist.
4503
4504 'dotglob'
4505 If set, Bash includes filenames beginning with a '.' in the
d233b485
CR
4506 results of filename expansion. The filenames '.' and '..'
4507 must always be matched explicitly, even if 'dotglob' is set.
a0c0a00f
CR
4508
4509 'execfail'
4510 If this is set, a non-interactive shell will not exit if it
4511 cannot execute the file specified as an argument to the 'exec'
4512 builtin command. An interactive shell does not exit if 'exec'
4513 fails.
4514
4515 'expand_aliases'
4516 If set, aliases are expanded as described below under Aliases,
4517 *note Aliases::. This option is enabled by default for
4518 interactive shells.
4519
4520 'extdebug'
4521 If set at shell invocation, arrange to execute the debugger
4522 profile before the shell starts, identical to the '--debugger'
4523 option. If set after invocation, behavior intended for use by
4524 debuggers is enabled:
4525
4526 1. The '-F' option to the 'declare' builtin (*note Bash
4527 Builtins::) displays the source file name and line number
4528 corresponding to each function name supplied as an
4529 argument.
4530
4531 2. If the command run by the 'DEBUG' trap returns a non-zero
4532 value, the next command is skipped and not executed.
4533
4534 3. If the command run by the 'DEBUG' trap returns a value of
4535 2, and the shell is executing in a subroutine (a shell
4536 function or a shell script executed by the '.' or
4537 'source' builtins), the shell simulates a call to
4538 'return'.
4539
4540 4. 'BASH_ARGC' and 'BASH_ARGV' are updated as described in
4541 their descriptions (*note Bash Variables::).
4542
4543 5. Function tracing is enabled: command substitution, shell
4544 functions, and subshells invoked with '( COMMAND )'
4545 inherit the 'DEBUG' and 'RETURN' traps.
4546
4547 6. Error tracing is enabled: command substitution, shell
4548 functions, and subshells invoked with '( COMMAND )'
4549 inherit the 'ERR' trap.
4550
4551 'extglob'
4552 If set, the extended pattern matching features described above
4553 (*note Pattern Matching::) are enabled.
4554
4555 'extquote'
4556 If set, '$'STRING'' and '$"STRING"' quoting is performed
4557 within '${PARAMETER}' expansions enclosed in double quotes.
4558 This option is enabled by default.
4559
4560 'failglob'
4561 If set, patterns which fail to match filenames during filename
4562 expansion result in an expansion error.
4563
4564 'force_fignore'
4565 If set, the suffixes specified by the 'FIGNORE' shell variable
4566 cause words to be ignored when performing word completion even
4567 if the ignored words are the only possible completions. *Note
4568 Bash Variables::, for a description of 'FIGNORE'. This option
4569 is enabled by default.
4570
4571 'globasciiranges'
4572 If set, range expressions used in pattern matching bracket
4573 expressions (*note Pattern Matching::) behave as if in the
4574 traditional C locale when performing comparisons. That is,
4575 the current locale's collating sequence is not taken into
4576 account, so 'b' will not collate between 'A' and 'B', and
4577 upper-case and lower-case ASCII characters will collate
4578 together.
4579
4580 'globstar'
4581 If set, the pattern '**' used in a filename expansion context
4582 will match all files and zero or more directories and
4583 subdirectories. If the pattern is followed by a '/', only
4584 directories and subdirectories match.
4585
4586 'gnu_errfmt'
4587 If set, shell error messages are written in the standard GNU
4588 error message format.
4589
4590 'histappend'
4591 If set, the history list is appended to the file named by the
4592 value of the 'HISTFILE' variable when the shell exits, rather
4593 than overwriting the file.
4594
4595 'histreedit'
4596 If set, and Readline is being used, a user is given the
4597 opportunity to re-edit a failed history substitution.
4598
4599 'histverify'
4600 If set, and Readline is being used, the results of history
4601 substitution are not immediately passed to the shell parser.
4602 Instead, the resulting line is loaded into the Readline
4603 editing buffer, allowing further modification.
4604
4605 'hostcomplete'
4606 If set, and Readline is being used, Bash will attempt to
4607 perform hostname completion when a word containing a '@' is
4608 being completed (*note Commands For Completion::). This
4609 option is enabled by default.
4610
4611 'huponexit'
4612 If set, Bash will send 'SIGHUP' to all jobs when an
4613 interactive login shell exits (*note Signals::).
4614
4615 'inherit_errexit'
4616 If set, command substitution inherits the value of the
4617 'errexit' option, instead of unsetting it in the subshell
4618 environment. This option is enabled when POSIX mode is
4619 enabled.
4620
4621 'interactive_comments'
4622 Allow a word beginning with '#' to cause that word and all
4623 remaining characters on that line to be ignored in an
4624 interactive shell. This option is enabled by default.
4625
4626 'lastpipe'
4627 If set, and job control is not active, the shell runs the last
4628 command of a pipeline not executed in the background in the
4629 current shell environment.
4630
4631 'lithist'
4632 If enabled, and the 'cmdhist' option is enabled, multi-line
4633 commands are saved to the history with embedded newlines
4634 rather than using semicolon separators where possible.
4635
d233b485
CR
4636 'localvar_inherit'
4637 If set, local variables inherit the value and attributes of a
4638 variable of the same name that exists at a previous scope
4639 before any new value is assigned. The NAMEREF attribute is
4640 not inherited.
4641
4642 'localvar_unset'
4643 If set, calling 'unset' on local variables in previous
4644 function scopes marks them so subsequent lookups find them
4645 unset until that function returns. This is identical to the
4646 behavior of unsetting local variables at the current function
4647 scope.
4648
a0c0a00f
CR
4649 'login_shell'
4650 The shell sets this option if it is started as a login shell
4651 (*note Invoking Bash::). The value may not be changed.
4652
4653 'mailwarn'
4654 If set, and a file that Bash is checking for mail has been
4655 accessed since the last time it was checked, the message '"The
4656 mail in MAILFILE has been read"' is displayed.
4657
4658 'no_empty_cmd_completion'
4659 If set, and Readline is being used, Bash will not attempt to
4660 search the 'PATH' for possible completions when completion is
4661 attempted on an empty line.
4662
4663 'nocaseglob'
4664 If set, Bash matches filenames in a case-insensitive fashion
4665 when performing filename expansion.
4666
4667 'nocasematch'
4668 If set, Bash matches patterns in a case-insensitive fashion
4669 when performing matching while executing 'case' or '[['
4670 conditional commands, when performing pattern substitution
4671 word expansions, or when filtering possible completions as
4672 part of programmable completion.
4673
4674 'nullglob'
4675 If set, Bash allows filename patterns which match no files to
4676 expand to a null string, rather than themselves.
4677
4678 'progcomp'
4679 If set, the programmable completion facilities (*note
4680 Programmable Completion::) are enabled. This option is
4681 enabled by default.
4682
d233b485
CR
4683 'progcomp_alias'
4684 If set, and programmable completion is enabled, Bash treats a
4685 command name that doesn't have any completions as a possible
4686 alias and attempts alias expansion. If it has an alias, Bash
4687 attempts programmable completion using the command word
4688 resulting from the expanded alias.
4689
a0c0a00f
CR
4690 'promptvars'
4691 If set, prompt strings undergo parameter expansion, command
4692 substitution, arithmetic expansion, and quote removal after
4693 being expanded as described below (*note Controlling the
4694 Prompt::). This option is enabled by default.
4695
4696 'restricted_shell'
4697 The shell sets this option if it is started in restricted mode
4698 (*note The Restricted Shell::). The value may not be changed.
4699 This is not reset when the startup files are executed,
4700 allowing the startup files to discover whether or not a shell
4701 is restricted.
4702
4703 'shift_verbose'
4704 If this is set, the 'shift' builtin prints an error message
4705 when the shift count exceeds the number of positional
4706 parameters.
4707
4708 'sourcepath'
4709 If set, the 'source' builtin uses the value of 'PATH' to find
4710 the directory containing the file supplied as an argument.
4711 This option is enabled by default.
4712
4713 'xpg_echo'
4714 If set, the 'echo' builtin expands backslash-escape sequences
4715 by default.
4716
4717 The return status when listing options is zero if all OPTNAMES are
4718 enabled, non-zero otherwise. When setting or unsetting options,
4719 the return status is zero unless an OPTNAME is not a valid shell
4720 option.
4721
4722\1f
4723File: bash.info, Node: Special Builtins, Prev: Modifying Shell Behavior, Up: Shell Builtin Commands
4724
47254.4 Special Builtins
4726====================
4727
4728For historical reasons, the POSIX standard has classified several
4729builtin commands as _special_. When Bash is executing in POSIX mode,
4730the special builtins differ from other builtin commands in three
4731respects:
4732
4733 1. Special builtins are found before shell functions during command
4734 lookup.
4735
4736 2. If a special builtin returns an error status, a non-interactive
4737 shell exits.
4738
4739 3. Assignment statements preceding the command stay in effect in the
4740 shell environment after the command completes.
4741
4742 When Bash is not executing in POSIX mode, these builtins behave no
4743differently than the rest of the Bash builtin commands. The Bash POSIX
4744mode is described in *note Bash POSIX Mode::.
4745
4746 These are the POSIX special builtins:
4747 break : . continue eval exec exit export readonly return set
4748 shift trap unset
4749
4750\1f
4751File: bash.info, Node: Shell Variables, Next: Bash Features, Prev: Shell Builtin Commands, Up: Top
4752
47535 Shell Variables
4754*****************
4755
4756* Menu:
4757
4758* Bourne Shell Variables:: Variables which Bash uses in the same way
4759 as the Bourne Shell.
4760* Bash Variables:: List of variables that exist in Bash.
4761
4762This chapter describes the shell variables that Bash uses. Bash
4763automatically assigns default values to a number of variables.
4764
4765\1f
4766File: bash.info, Node: Bourne Shell Variables, Next: Bash Variables, Up: Shell Variables
4767
47685.1 Bourne Shell Variables
4769==========================
4770
4771Bash uses certain shell variables in the same way as the Bourne shell.
4772In some cases, Bash assigns a default value to the variable.
4773
4774'CDPATH'
4775 A colon-separated list of directories used as a search path for the
4776 'cd' builtin command.
4777
4778'HOME'
4779 The current user's home directory; the default for the 'cd' builtin
4780 command. The value of this variable is also used by tilde
4781 expansion (*note Tilde Expansion::).
4782
4783'IFS'
4784 A list of characters that separate fields; used when the shell
4785 splits words as part of expansion.
4786
4787'MAIL'
4788 If this parameter is set to a filename or directory name and the
4789 'MAILPATH' variable is not set, Bash informs the user of the
4790 arrival of mail in the specified file or Maildir-format directory.
4791
4792'MAILPATH'
4793 A colon-separated list of filenames which the shell periodically
4794 checks for new mail. Each list entry can specify the message that
4795 is printed when new mail arrives in the mail file by separating the
4796 filename from the message with a '?'. When used in the text of the
4797 message, '$_' expands to the name of the current mail file.
4798
4799'OPTARG'
4800 The value of the last option argument processed by the 'getopts'
4801 builtin.
4802
4803'OPTIND'
4804 The index of the last option argument processed by the 'getopts'
4805 builtin.
4806
4807'PATH'
4808 A colon-separated list of directories in which the shell looks for
4809 commands. A zero-length (null) directory name in the value of
4810 'PATH' indicates the current directory. A null directory name may
4811 appear as two adjacent colons, or as an initial or trailing colon.
4812
4813'PS1'
4814 The primary prompt string. The default value is '\s-\v\$ '. *Note
4815 Controlling the Prompt::, for the complete list of escape sequences
4816 that are expanded before 'PS1' is displayed.
4817
4818'PS2'
d233b485
CR
4819 The secondary prompt string. The default value is '> '. 'PS2' is
4820 expanded in the same way as 'PS1' before being displayed.
a0c0a00f
CR
4821
4822\1f
4823File: bash.info, Node: Bash Variables, Prev: Bourne Shell Variables, Up: Shell Variables
4824
48255.2 Bash Variables
4826==================
4827
4828These variables are set or used by Bash, but other shells do not
4829normally treat them specially.
4830
4831 A few variables used by Bash are described in different chapters:
4832variables for controlling the job control facilities (*note Job Control
4833Variables::).
4834
4835'BASH'
4836 The full pathname used to execute the current instance of Bash.
4837
4838'BASHOPTS'
4839 A colon-separated list of enabled shell options. Each word in the
4840 list is a valid argument for the '-s' option to the 'shopt' builtin
4841 command (*note The Shopt Builtin::). The options appearing in
4842 'BASHOPTS' are those reported as 'on' by 'shopt'. If this variable
4843 is in the environment when Bash starts up, each shell option in the
4844 list will be enabled before reading any startup files. This
4845 variable is readonly.
4846
4847'BASHPID'
4848 Expands to the process ID of the current Bash process. This
4849 differs from '$$' under certain circumstances, such as subshells
d233b485
CR
4850 that do not require Bash to be re-initialized. Assignments to
4851 'BASHPID' have no effect. If 'BASHPID' is unset, it loses its
4852 special properties, even if it is subsequently reset.
a0c0a00f
CR
4853
4854'BASH_ALIASES'
4855 An associative array variable whose members correspond to the
4856 internal list of aliases as maintained by the 'alias' builtin.
4857 (*note Bourne Shell Builtins::). Elements added to this array
4858 appear in the alias list; however, unsetting array elements
4859 currently does not cause aliases to be removed from the alias list.
4860 If 'BASH_ALIASES' is unset, it loses its special properties, even
4861 if it is subsequently reset.
4862
4863'BASH_ARGC'
4864 An array variable whose values are the number of parameters in each
4865 frame of the current bash execution call stack. The number of
4866 parameters to the current subroutine (shell function or script
4867 executed with '.' or 'source') is at the top of the stack. When a
4868 subroutine is executed, the number of parameters passed is pushed
4869 onto 'BASH_ARGC'. The shell sets 'BASH_ARGC' only when in extended
4870 debugging mode (see *note The Shopt Builtin:: for a description of
d233b485
CR
4871 the 'extdebug' option to the 'shopt' builtin). Setting 'extdebug'
4872 after the shell has started to execute a script, or referencing
4873 this variable when 'extdebug' is not set, may result in
4874 inconsistent values.
a0c0a00f
CR
4875
4876'BASH_ARGV'
4877 An array variable containing all of the parameters in the current
4878 bash execution call stack. The final parameter of the last
4879 subroutine call is at the top of the stack; the first parameter of
4880 the initial call is at the bottom. When a subroutine is executed,
4881 the parameters supplied are pushed onto 'BASH_ARGV'. The shell
4882 sets 'BASH_ARGV' only when in extended debugging mode (see *note
4883 The Shopt Builtin:: for a description of the 'extdebug' option to
d233b485
CR
4884 the 'shopt' builtin). Setting 'extdebug' after the shell has
4885 started to execute a script, or referencing this variable when
4886 'extdebug' is not set, may result in inconsistent values.
4887
4888'BASH_ARGV0'
4889 When referenced, this variable expands to the name of the shell or
4890 shell script (identical to '$0'; *Note Special Parameters::, for
4891 the description of special parameter 0). Assignment to
4892 'BASH_ARGV0' causes the value assigned to also be assigned to '$0'.
4893 If 'BASH_ARGV0' is unset, it loses its special properties, even if
4894 it is subsequently reset.
a0c0a00f
CR
4895
4896'BASH_CMDS'
4897 An associative array variable whose members correspond to the
4898 internal hash table of commands as maintained by the 'hash' builtin
4899 (*note Bourne Shell Builtins::). Elements added to this array
4900 appear in the hash table; however, unsetting array elements
4901 currently does not cause command names to be removed from the hash
4902 table. If 'BASH_CMDS' is unset, it loses its special properties,
4903 even if it is subsequently reset.
4904
4905'BASH_COMMAND'
4906 The command currently being executed or about to be executed,
4907 unless the shell is executing a command as the result of a trap, in
4908 which case it is the command executing at the time of the trap.
4909
4910'BASH_COMPAT'
4911 The value is used to set the shell's compatibility level. *Note
4912 The Shopt Builtin::, for a description of the various compatibility
4913 levels and their effects. The value may be a decimal number (e.g.,
4914 4.2) or an integer (e.g., 42) corresponding to the desired
4915 compatibility level. If 'BASH_COMPAT' is unset or set to the empty
4916 string, the compatibility level is set to the default for the
4917 current version. If 'BASH_COMPAT' is set to a value that is not
4918 one of the valid compatibility levels, the shell prints an error
4919 message and sets the compatibility level to the default for the
4920 current version. The valid compatibility levels correspond to the
4921 compatibility options accepted by the 'shopt' builtin described
4922 above (for example, COMPAT42 means that 4.2 and 42 are valid
4923 values). The current version is also a valid value.
4924
4925'BASH_ENV'
4926 If this variable is set when Bash is invoked to execute a shell
4927 script, its value is expanded and used as the name of a startup
4928 file to read before executing the script. *Note Bash Startup
4929 Files::.
4930
4931'BASH_EXECUTION_STRING'
4932 The command argument to the '-c' invocation option.
4933
4934'BASH_LINENO'
4935 An array variable whose members are the line numbers in source
4936 files where each corresponding member of FUNCNAME was invoked.
4937 '${BASH_LINENO[$i]}' is the line number in the source file
4938 ('${BASH_SOURCE[$i+1]}') where '${FUNCNAME[$i]}' was called (or
4939 '${BASH_LINENO[$i-1]}' if referenced within another shell
4940 function). Use 'LINENO' to obtain the current line number.
4941
4942'BASH_LOADABLES_PATH'
4943 A colon-separated list of directories in which the shell looks for
4944 dynamically loadable builtins specified by the 'enable' command.
4945
4946'BASH_REMATCH'
4947 An array variable whose members are assigned by the '=~' binary
4948 operator to the '[[' conditional command (*note Conditional
4949 Constructs::). The element with index 0 is the portion of the
4950 string matching the entire regular expression. The element with
4951 index N is the portion of the string matching the Nth parenthesized
4952 subexpression. This variable is read-only.
4953
4954'BASH_SOURCE'
4955 An array variable whose members are the source filenames where the
4956 corresponding shell function names in the 'FUNCNAME' array variable
4957 are defined. The shell function '${FUNCNAME[$i]}' is defined in
4958 the file '${BASH_SOURCE[$i]}' and called from
4959 '${BASH_SOURCE[$i+1]}'
4960
4961'BASH_SUBSHELL'
4962 Incremented by one within each subshell or subshell environment
4963 when the shell begins executing in that environment. The initial
4964 value is 0.
4965
4966'BASH_VERSINFO'
4967 A readonly array variable (*note Arrays::) whose members hold
4968 version information for this instance of Bash. The values assigned
4969 to the array members are as follows:
4970
4971 'BASH_VERSINFO[0]'
4972 The major version number (the RELEASE).
4973
4974 'BASH_VERSINFO[1]'
4975 The minor version number (the VERSION).
4976
4977 'BASH_VERSINFO[2]'
4978 The patch level.
4979
4980 'BASH_VERSINFO[3]'
4981 The build version.
4982
4983 'BASH_VERSINFO[4]'
4984 The release status (e.g., BETA1).
4985
4986 'BASH_VERSINFO[5]'
4987 The value of 'MACHTYPE'.
4988
4989'BASH_VERSION'
4990 The version number of the current instance of Bash.
4991
4992'BASH_XTRACEFD'
4993 If set to an integer corresponding to a valid file descriptor, Bash
4994 will write the trace output generated when 'set -x' is enabled to
4995 that file descriptor. This allows tracing output to be separated
4996 from diagnostic and error messages. The file descriptor is closed
4997 when 'BASH_XTRACEFD' is unset or assigned a new value. Unsetting
4998 'BASH_XTRACEFD' or assigning it the empty string causes the trace
4999 output to be sent to the standard error. Note that setting
5000 'BASH_XTRACEFD' to 2 (the standard error file descriptor) and then
5001 unsetting it will result in the standard error being closed.
5002
5003'CHILD_MAX'
5004 Set the number of exited child status values for the shell to
5005 remember. Bash will not allow this value to be decreased below a
5006 POSIX-mandated minimum, and there is a maximum value (currently
5007 8192) that this may not exceed. The minimum value is
5008 system-dependent.
5009
5010'COLUMNS'
5011 Used by the 'select' command to determine the terminal width when
5012 printing selection lists. Automatically set if the 'checkwinsize'
5013 option is enabled (*note The Shopt Builtin::), or in an interactive
5014 shell upon receipt of a 'SIGWINCH'.
5015
5016'COMP_CWORD'
5017 An index into '${COMP_WORDS}' of the word containing the current
5018 cursor position. This variable is available only in shell
5019 functions invoked by the programmable completion facilities (*note
5020 Programmable Completion::).
5021
5022'COMP_LINE'
5023 The current command line. This variable is available only in shell
5024 functions and external commands invoked by the programmable
5025 completion facilities (*note Programmable Completion::).
5026
5027'COMP_POINT'
5028 The index of the current cursor position relative to the beginning
5029 of the current command. If the current cursor position is at the
5030 end of the current command, the value of this variable is equal to
5031 '${#COMP_LINE}'. This variable is available only in shell
5032 functions and external commands invoked by the programmable
5033 completion facilities (*note Programmable Completion::).
5034
5035'COMP_TYPE'
5036 Set to an integer value corresponding to the type of completion
5037 attempted that caused a completion function to be called: TAB, for
5038 normal completion, '?', for listing completions after successive
5039 tabs, '!', for listing alternatives on partial word completion,
5040 '@', to list completions if the word is not unmodified, or '%', for
5041 menu completion. This variable is available only in shell
5042 functions and external commands invoked by the programmable
5043 completion facilities (*note Programmable Completion::).
5044
5045'COMP_KEY'
5046 The key (or final key of a key sequence) used to invoke the current
5047 completion function.
5048
5049'COMP_WORDBREAKS'
5050 The set of characters that the Readline library treats as word
5051 separators when performing word completion. If 'COMP_WORDBREAKS'
5052 is unset, it loses its special properties, even if it is
5053 subsequently reset.
5054
5055'COMP_WORDS'
5056 An array variable consisting of the individual words in the current
5057 command line. The line is split into words as Readline would split
5058 it, using 'COMP_WORDBREAKS' as described above. This variable is
5059 available only in shell functions invoked by the programmable
5060 completion facilities (*note Programmable Completion::).
5061
5062'COMPREPLY'
5063 An array variable from which Bash reads the possible completions
5064 generated by a shell function invoked by the programmable
5065 completion facility (*note Programmable Completion::). Each array
5066 element contains one possible completion.
5067
5068'COPROC'
5069 An array variable created to hold the file descriptors for output
5070 from and input to an unnamed coprocess (*note Coprocesses::).
5071
5072'DIRSTACK'
5073 An array variable containing the current contents of the directory
5074 stack. Directories appear in the stack in the order they are
5075 displayed by the 'dirs' builtin. Assigning to members of this
5076 array variable may be used to modify directories already in the
5077 stack, but the 'pushd' and 'popd' builtins must be used to add and
5078 remove directories. Assignment to this variable will not change
5079 the current directory. If 'DIRSTACK' is unset, it loses its
5080 special properties, even if it is subsequently reset.
5081
5082'EMACS'
5083 If Bash finds this variable in the environment when the shell
5084 starts with value 't', it assumes that the shell is running in an
5085 Emacs shell buffer and disables line editing.
5086
5087'ENV'
5088 Similar to 'BASH_ENV'; used when the shell is invoked in POSIX Mode
5089 (*note Bash POSIX Mode::).
5090
d233b485
CR
5091'EPOCHREALTIME'
5092 Each time this parameter is referenced, it expands to the number of
5093 seconds since the Unix Epoch as a floating point value with
5094 micro-second granularity (see the documentation for the C library
5095 function TIME for the definition of Epoch). Assignments to
5096 'EPOCHREALTIME' are ignored. If 'EPOCHREALTIME' is unset, it loses
5097 its special properties, even if it is subsequently reset.
5098
5099'EPOCHSECONDS'
5100 Each time this parameter is referenced, it expands to the number of
5101 seconds since the Unix Epoch (see the documentation for the C
5102 library function TIME for the definition of Epoch). Assignments to
5103 'EPOCHSECONDS' are ignored. If 'EPOCHSECONDS' is unset, it loses
5104 its special properties, even if it is subsequently reset.
5105
a0c0a00f
CR
5106'EUID'
5107 The numeric effective user id of the current user. This variable
5108 is readonly.
5109
5110'EXECIGNORE'
5111 A colon-separated list of shell patterns (*note Pattern Matching::)
5112 defining the list of filenames to be ignored by command search
5113 using 'PATH'. Files whose full pathnames match one of these
5114 patterns are not considered executable files for the purposes of
5115 completion and command execution via 'PATH' lookup. This does not
5116 affect the behavior of the '[', 'test', and '[[' commands. Full
5117 pathnames in the command hash table are not subject to
5118 'EXECIGNORE'. Use this variable to ignore shared library files
5119 that have the executable bit set, but are not executable files.
5120 The pattern matching honors the setting of the 'extglob' shell
5121 option.
5122
5123'FCEDIT'
5124 The editor used as a default by the '-e' option to the 'fc' builtin
5125 command.
5126
5127'FIGNORE'
5128 A colon-separated list of suffixes to ignore when performing
5129 filename completion. A filename whose suffix matches one of the
5130 entries in 'FIGNORE' is excluded from the list of matched
5131 filenames. A sample value is '.o:~'
5132
5133'FUNCNAME'
5134 An array variable containing the names of all shell functions
5135 currently in the execution call stack. The element with index 0 is
5136 the name of any currently-executing shell function. The
5137 bottom-most element (the one with the highest index) is '"main"'.
5138 This variable exists only when a shell function is executing.
5139 Assignments to 'FUNCNAME' have no effect. If 'FUNCNAME' is unset,
5140 it loses its special properties, even if it is subsequently reset.
5141
5142 This variable can be used with 'BASH_LINENO' and 'BASH_SOURCE'.
5143 Each element of 'FUNCNAME' has corresponding elements in
5144 'BASH_LINENO' and 'BASH_SOURCE' to describe the call stack. For
5145 instance, '${FUNCNAME[$i]}' was called from the file
5146 '${BASH_SOURCE[$i+1]}' at line number '${BASH_LINENO[$i]}'. The
5147 'caller' builtin displays the current call stack using this
5148 information.
5149
5150'FUNCNEST'
5151 If set to a numeric value greater than 0, defines a maximum
5152 function nesting level. Function invocations that exceed this
5153 nesting level will cause the current command to abort.
5154
5155'GLOBIGNORE'
d233b485
CR
5156 A colon-separated list of patterns defining the set of file names
5157 to be ignored by filename expansion. If a file name matched by a
a0c0a00f
CR
5158 filename expansion pattern also matches one of the patterns in
5159 'GLOBIGNORE', it is removed from the list of matches. The pattern
5160 matching honors the setting of the 'extglob' shell option.
5161
5162'GROUPS'
5163 An array variable containing the list of groups of which the
5164 current user is a member. Assignments to 'GROUPS' have no effect.
5165 If 'GROUPS' is unset, it loses its special properties, even if it
5166 is subsequently reset.
5167
5168'histchars'
5169 Up to three characters which control history expansion, quick
5170 substitution, and tokenization (*note History Interaction::). The
5171 first character is the HISTORY EXPANSION character, that is, the
5172 character which signifies the start of a history expansion,
5173 normally '!'. The second character is the character which
5174 signifies 'quick substitution' when seen as the first character on
5175 a line, normally '^'. The optional third character is the
5176 character which indicates that the remainder of the line is a
5177 comment when found as the first character of a word, usually '#'.
5178 The history comment character causes history substitution to be
5179 skipped for the remaining words on the line. It does not
5180 necessarily cause the shell parser to treat the rest of the line as
5181 a comment.
5182
5183'HISTCMD'
5184 The history number, or index in the history list, of the current
5185 command. If 'HISTCMD' is unset, it loses its special properties,
5186 even if it is subsequently reset.
5187
5188'HISTCONTROL'
5189 A colon-separated list of values controlling how commands are saved
5190 on the history list. If the list of values includes 'ignorespace',
5191 lines which begin with a space character are not saved in the
5192 history list. A value of 'ignoredups' causes lines which match the
5193 previous history entry to not be saved. A value of 'ignoreboth' is
5194 shorthand for 'ignorespace' and 'ignoredups'. A value of
5195 'erasedups' causes all previous lines matching the current line to
5196 be removed from the history list before that line is saved. Any
5197 value not in the above list is ignored. If 'HISTCONTROL' is unset,
5198 or does not include a valid value, all lines read by the shell
5199 parser are saved on the history list, subject to the value of
5200 'HISTIGNORE'. The second and subsequent lines of a multi-line
5201 compound command are not tested, and are added to the history
5202 regardless of the value of 'HISTCONTROL'.
5203
5204'HISTFILE'
5205 The name of the file to which the command history is saved. The
5206 default value is '~/.bash_history'.
5207
5208'HISTFILESIZE'
5209 The maximum number of lines contained in the history file. When
5210 this variable is assigned a value, the history file is truncated,
5211 if necessary, to contain no more than that number of lines by
5212 removing the oldest entries. The history file is also truncated to
5213 this size after writing it when a shell exits. If the value is 0,
5214 the history file is truncated to zero size. Non-numeric values and
5215 numeric values less than zero inhibit truncation. The shell sets
5216 the default value to the value of 'HISTSIZE' after reading any
5217 startup files.
5218
5219'HISTIGNORE'
5220 A colon-separated list of patterns used to decide which command
5221 lines should be saved on the history list. Each pattern is
5222 anchored at the beginning of the line and must match the complete
5223 line (no implicit '*' is appended). Each pattern is tested against
5224 the line after the checks specified by 'HISTCONTROL' are applied.
5225 In addition to the normal shell pattern matching characters, '&'
5226 matches the previous history line. '&' may be escaped using a
5227 backslash; the backslash is removed before attempting a match. The
5228 second and subsequent lines of a multi-line compound command are
5229 not tested, and are added to the history regardless of the value of
5230 'HISTIGNORE'. The pattern matching honors the setting of the
5231 'extglob' shell option.
5232
5233 'HISTIGNORE' subsumes the function of 'HISTCONTROL'. A pattern of
5234 '&' is identical to 'ignoredups', and a pattern of '[ ]*' is
5235 identical to 'ignorespace'. Combining these two patterns,
5236 separating them with a colon, provides the functionality of
5237 'ignoreboth'.
5238
5239'HISTSIZE'
5240 The maximum number of commands to remember on the history list. If
5241 the value is 0, commands are not saved in the history list.
5242 Numeric values less than zero result in every command being saved
5243 on the history list (there is no limit). The shell sets the
5244 default value to 500 after reading any startup files.
5245
5246'HISTTIMEFORMAT'
5247 If this variable is set and not null, its value is used as a format
5248 string for STRFTIME to print the time stamp associated with each
5249 history entry displayed by the 'history' builtin. If this variable
5250 is set, time stamps are written to the history file so they may be
5251 preserved across shell sessions. This uses the history comment
5252 character to distinguish timestamps from other history lines.
5253
5254'HOSTFILE'
5255 Contains the name of a file in the same format as '/etc/hosts' that
5256 should be read when the shell needs to complete a hostname. The
5257 list of possible hostname completions may be changed while the
5258 shell is running; the next time hostname completion is attempted
5259 after the value is changed, Bash adds the contents of the new file
5260 to the existing list. If 'HOSTFILE' is set, but has no value, or
5261 does not name a readable file, Bash attempts to read '/etc/hosts'
5262 to obtain the list of possible hostname completions. When
5263 'HOSTFILE' is unset, the hostname list is cleared.
5264
5265'HOSTNAME'
5266 The name of the current host.
5267
5268'HOSTTYPE'
5269 A string describing the machine Bash is running on.
5270
5271'IGNOREEOF'
5272 Controls the action of the shell on receipt of an 'EOF' character
5273 as the sole input. If set, the value denotes the number of
5274 consecutive 'EOF' characters that can be read as the first
5275 character on an input line before the shell will exit. If the
d233b485 5276 variable exists but does not have a numeric value, or has no value,
a0c0a00f
CR
5277 then the default is 10. If the variable does not exist, then 'EOF'
5278 signifies the end of input to the shell. This is only in effect
5279 for interactive shells.
5280
5281'INPUTRC'
5282 The name of the Readline initialization file, overriding the
5283 default of '~/.inputrc'.
5284
d233b485
CR
5285'INSIDE_EMACS'
5286 If Bash finds this variable in the environment when the shell
5287 starts, it assumes that the shell is running in an Emacs shell
5288 buffer and may disable line editing depending on the value of
5289 'TERM'.
5290
a0c0a00f
CR
5291'LANG'
5292 Used to determine the locale category for any category not
5293 specifically selected with a variable starting with 'LC_'.
5294
5295'LC_ALL'
5296 This variable overrides the value of 'LANG' and any other 'LC_'
5297 variable specifying a locale category.
5298
5299'LC_COLLATE'
5300 This variable determines the collation order used when sorting the
5301 results of filename expansion, and determines the behavior of range
5302 expressions, equivalence classes, and collating sequences within
5303 filename expansion and pattern matching (*note Filename
5304 Expansion::).
5305
5306'LC_CTYPE'
5307 This variable determines the interpretation of characters and the
5308 behavior of character classes within filename expansion and pattern
5309 matching (*note Filename Expansion::).
5310
5311'LC_MESSAGES'
5312 This variable determines the locale used to translate double-quoted
5313 strings preceded by a '$' (*note Locale Translation::).
5314
5315'LC_NUMERIC'
5316 This variable determines the locale category used for number
5317 formatting.
5318
5319'LC_TIME'
5320 This variable determines the locale category used for data and time
5321 formatting.
5322
5323'LINENO'
5324 The line number in the script or shell function currently
5325 executing.
5326
5327'LINES'
5328 Used by the 'select' command to determine the column length for
5329 printing selection lists. Automatically set if the 'checkwinsize'
5330 option is enabled (*note The Shopt Builtin::), or in an interactive
5331 shell upon receipt of a 'SIGWINCH'.
5332
5333'MACHTYPE'
5334 A string that fully describes the system type on which Bash is
5335 executing, in the standard GNU CPU-COMPANY-SYSTEM format.
5336
5337'MAILCHECK'
5338 How often (in seconds) that the shell should check for mail in the
5339 files specified in the 'MAILPATH' or 'MAIL' variables. The default
5340 is 60 seconds. When it is time to check for mail, the shell does
5341 so before displaying the primary prompt. If this variable is
5342 unset, or set to a value that is not a number greater than or equal
5343 to zero, the shell disables mail checking.
5344
5345'MAPFILE'
5346 An array variable created to hold the text read by the 'mapfile'
5347 builtin when no variable name is supplied.
5348
5349'OLDPWD'
5350 The previous working directory as set by the 'cd' builtin.
5351
5352'OPTERR'
5353 If set to the value 1, Bash displays error messages generated by
5354 the 'getopts' builtin command.
5355
5356'OSTYPE'
5357 A string describing the operating system Bash is running on.
5358
5359'PIPESTATUS'
5360 An array variable (*note Arrays::) containing a list of exit status
5361 values from the processes in the most-recently-executed foreground
5362 pipeline (which may contain only a single command).
5363
5364'POSIXLY_CORRECT'
5365 If this variable is in the environment when Bash starts, the shell
5366 enters POSIX mode (*note Bash POSIX Mode::) before reading the
5367 startup files, as if the '--posix' invocation option had been
5368 supplied. If it is set while the shell is running, Bash enables
5369 POSIX mode, as if the command
5370 set -o posix
d233b485
CR
5371 had been executed. When the shell enters POSIX mode, it sets this
5372 variable if it was not already set.
a0c0a00f
CR
5373
5374'PPID'
5375 The process ID of the shell's parent process. This variable is
5376 readonly.
5377
5378'PROMPT_COMMAND'
5379 If set, the value is interpreted as a command to execute before the
5380 printing of each primary prompt ('$PS1').
5381
5382'PROMPT_DIRTRIM'
5383 If set to a number greater than zero, the value is used as the
5384 number of trailing directory components to retain when expanding
5385 the '\w' and '\W' prompt string escapes (*note Controlling the
5386 Prompt::). Characters removed are replaced with an ellipsis.
5387
5388'PS0'
5389 The value of this parameter is expanded like PS1 and displayed by
5390 interactive shells after reading a command and before the command
5391 is executed.
5392
5393'PS3'
5394 The value of this variable is used as the prompt for the 'select'
5395 command. If this variable is not set, the 'select' command prompts
5396 with '#? '
5397
5398'PS4'
d233b485
CR
5399 The value of this parameter is expanded like PS1 and the expanded
5400 value is the prompt printed before the command line is echoed when
5401 the '-x' option is set (*note The Set Builtin::). The first
5402 character of the expanded value is replicated multiple times, as
5403 necessary, to indicate multiple levels of indirection. The default
5404 is '+ '.
a0c0a00f
CR
5405
5406'PWD'
5407 The current working directory as set by the 'cd' builtin.
5408
5409'RANDOM'
5410 Each time this parameter is referenced, a random integer between 0
5411 and 32767 is generated. Assigning a value to this variable seeds
5412 the random number generator.
5413
5414'READLINE_LINE'
5415 The contents of the Readline line buffer, for use with 'bind -x'
5416 (*note Bash Builtins::).
5417
5418'READLINE_POINT'
5419 The position of the insertion point in the Readline line buffer,
5420 for use with 'bind -x' (*note Bash Builtins::).
5421
5422'REPLY'
5423 The default variable for the 'read' builtin.
5424
5425'SECONDS'
5426 This variable expands to the number of seconds since the shell was
5427 started. Assignment to this variable resets the count to the value
5428 assigned, and the expanded value becomes the value assigned plus
5429 the number of seconds since the assignment.
5430
5431'SHELL'
5432 The full pathname to the shell is kept in this environment
5433 variable. If it is not set when the shell starts, Bash assigns to
5434 it the full pathname of the current user's login shell.
5435
5436'SHELLOPTS'
5437 A colon-separated list of enabled shell options. Each word in the
5438 list is a valid argument for the '-o' option to the 'set' builtin
5439 command (*note The Set Builtin::). The options appearing in
5440 'SHELLOPTS' are those reported as 'on' by 'set -o'. If this
5441 variable is in the environment when Bash starts up, each shell
5442 option in the list will be enabled before reading any startup
5443 files. This variable is readonly.
5444
5445'SHLVL'
5446 Incremented by one each time a new instance of Bash is started.
5447 This is intended to be a count of how deeply your Bash shells are
5448 nested.
5449
5450'TIMEFORMAT'
5451 The value of this parameter is used as a format string specifying
5452 how the timing information for pipelines prefixed with the 'time'
5453 reserved word should be displayed. The '%' character introduces an
5454 escape sequence that is expanded to a time value or other
5455 information. The escape sequences and their meanings are as
5456 follows; the braces denote optional portions.
5457
5458 '%%'
5459 A literal '%'.
5460
5461 '%[P][l]R'
5462 The elapsed time in seconds.
5463
5464 '%[P][l]U'
5465 The number of CPU seconds spent in user mode.
5466
5467 '%[P][l]S'
5468 The number of CPU seconds spent in system mode.
5469
5470 '%P'
5471 The CPU percentage, computed as (%U + %S) / %R.
5472
5473 The optional P is a digit specifying the precision, the number of
5474 fractional digits after a decimal point. A value of 0 causes no
5475 decimal point or fraction to be output. At most three places after
5476 the decimal point may be specified; values of P greater than 3 are
5477 changed to 3. If P is not specified, the value 3 is used.
5478
5479 The optional 'l' specifies a longer format, including minutes, of
5480 the form MMmSS.FFs. The value of P determines whether or not the
5481 fraction is included.
5482
5483 If this variable is not set, Bash acts as if it had the value
5484 $'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS'
5485 If the value is null, no timing information is displayed. A
5486 trailing newline is added when the format string is displayed.
5487
5488'TMOUT'
5489 If set to a value greater than zero, 'TMOUT' is treated as the
5490 default timeout for the 'read' builtin (*note Bash Builtins::).
5491 The 'select' command (*note Conditional Constructs::) terminates if
5492 input does not arrive after 'TMOUT' seconds when input is coming
5493 from a terminal.
5494
5495 In an interactive shell, the value is interpreted as the number of
5496 seconds to wait for a line of input after issuing the primary
5497 prompt. Bash terminates after waiting for that number of seconds
5498 if a complete line of input does not arrive.
5499
5500'TMPDIR'
5501 If set, Bash uses its value as the name of a directory in which
5502 Bash creates temporary files for the shell's use.
5503
5504'UID'
5505 The numeric real user id of the current user. This variable is
5506 readonly.
5507
5508\1f
5509File: bash.info, Node: Bash Features, Next: Job Control, Prev: Shell Variables, Up: Top
5510
55116 Bash Features
5512***************
5513
5514This chapter describes features unique to Bash.
5515
5516* Menu:
5517
5518* Invoking Bash:: Command line options that you can give
5519 to Bash.
5520* Bash Startup Files:: When and how Bash executes scripts.
5521* Interactive Shells:: What an interactive shell is.
5522* Bash Conditional Expressions:: Primitives used in composing expressions for
5523 the 'test' builtin.
5524* Shell Arithmetic:: Arithmetic on shell variables.
5525* Aliases:: Substituting one command for another.
5526* Arrays:: Array Variables.
5527* The Directory Stack:: History of visited directories.
5528* Controlling the Prompt:: Customizing the various prompt strings.
5529* The Restricted Shell:: A more controlled mode of shell execution.
5530* Bash POSIX Mode:: Making Bash behave more closely to what
5531 the POSIX standard specifies.
5532
5533\1f
5534File: bash.info, Node: Invoking Bash, Next: Bash Startup Files, Up: Bash Features
5535
55366.1 Invoking Bash
5537=================
5538
d233b485
CR
5539 bash [long-opt] [-ir] [-abefhkmnptuvxdBCDHP] [-o OPTION]
5540 [-O SHOPT_OPTION] [ARGUMENT ...]
5541 bash [long-opt] [-abefhkmnptuvxdBCDHP] [-o OPTION]
5542 [-O SHOPT_OPTION] -c STRING [ARGUMENT ...]
5543 bash [long-opt] -s [-abefhkmnptuvxdBCDHP] [-o OPTION]
5544 [-O SHOPT_OPTION] [ARGUMENT ...]
a0c0a00f
CR
5545
5546 All of the single-character options used with the 'set' builtin
5547(*note The Set Builtin::) can be used as options when the shell is
5548invoked. In addition, there are several multi-character options that
5549you can use. These options must appear on the command line before the
5550single-character options to be recognized.
5551
5552'--debugger'
5553 Arrange for the debugger profile to be executed before the shell
5554 starts. Turns on extended debugging mode (see *note The Shopt
5555 Builtin:: for a description of the 'extdebug' option to the 'shopt'
5556 builtin).
5557
5558'--dump-po-strings'
5559 A list of all double-quoted strings preceded by '$' is printed on
5560 the standard output in the GNU 'gettext' PO (portable object) file
5561 format. Equivalent to '-D' except for the output format.
5562
5563'--dump-strings'
5564 Equivalent to '-D'.
5565
5566'--help'
5567 Display a usage message on standard output and exit successfully.
5568
5569'--init-file FILENAME'
5570'--rcfile FILENAME'
5571 Execute commands from FILENAME (instead of '~/.bashrc') in an
5572 interactive shell.
5573
5574'--login'
5575 Equivalent to '-l'.
5576
5577'--noediting'
5578 Do not use the GNU Readline library (*note Command Line Editing::)
5579 to read command lines when the shell is interactive.
5580
5581'--noprofile'
5582 Don't load the system-wide startup file '/etc/profile' or any of
5583 the personal initialization files '~/.bash_profile',
5584 '~/.bash_login', or '~/.profile' when Bash is invoked as a login
5585 shell.
5586
5587'--norc'
5588 Don't read the '~/.bashrc' initialization file in an interactive
5589 shell. This is on by default if the shell is invoked as 'sh'.
5590
5591'--posix'
5592 Change the behavior of Bash where the default operation differs
5593 from the POSIX standard to match the standard. This is intended to
5594 make Bash behave as a strict superset of that standard. *Note Bash
5595 POSIX Mode::, for a description of the Bash POSIX mode.
5596
5597'--restricted'
5598 Make the shell a restricted shell (*note The Restricted Shell::).
5599
5600'--verbose'
5601 Equivalent to '-v'. Print shell input lines as they're read.
5602
5603'--version'
5604 Show version information for this instance of Bash on the standard
5605 output and exit successfully.
5606
5607 There are several single-character options that may be supplied at
5608invocation which are not available with the 'set' builtin.
5609
5610'-c'
5611 Read and execute commands from the first non-option argument
5612 COMMAND_STRING, then exit. If there are arguments after the
5613 COMMAND_STRING, the first argument is assigned to '$0' and any
5614 remaining arguments are assigned to the positional parameters. The
5615 assignment to '$0' sets the name of the shell, which is used in
5616 warning and error messages.
5617
5618'-i'
5619 Force the shell to run interactively. Interactive shells are
5620 described in *note Interactive Shells::.
5621
5622'-l'
5623 Make this shell act as if it had been directly invoked by login.
5624 When the shell is interactive, this is equivalent to starting a
5625 login shell with 'exec -l bash'. When the shell is not
5626 interactive, the login shell startup files will be executed. 'exec
5627 bash -l' or 'exec bash --login' will replace the current shell with
5628 a Bash login shell. *Note Bash Startup Files::, for a description
5629 of the special behavior of a login shell.
5630
5631'-r'
5632 Make the shell a restricted shell (*note The Restricted Shell::).
5633
5634'-s'
5635 If this option is present, or if no arguments remain after option
5636 processing, then commands are read from the standard input. This
5637 option allows the positional parameters to be set when invoking an
d233b485 5638 interactive shell or when reading input through a pipe.
a0c0a00f
CR
5639
5640'-D'
5641 A list of all double-quoted strings preceded by '$' is printed on
5642 the standard output. These are the strings that are subject to
5643 language translation when the current locale is not 'C' or 'POSIX'
5644 (*note Locale Translation::). This implies the '-n' option; no
5645 commands will be executed.
5646
5647'[-+]O [SHOPT_OPTION]'
5648 SHOPT_OPTION is one of the shell options accepted by the 'shopt'
5649 builtin (*note The Shopt Builtin::). If SHOPT_OPTION is present,
5650 '-O' sets the value of that option; '+O' unsets it. If
5651 SHOPT_OPTION is not supplied, the names and values of the shell
5652 options accepted by 'shopt' are printed on the standard output. If
5653 the invocation option is '+O', the output is displayed in a format
5654 that may be reused as input.
5655
5656'--'
5657 A '--' signals the end of options and disables further option
5658 processing. Any arguments after the '--' are treated as filenames
5659 and arguments.
5660
5661 A _login_ shell is one whose first character of argument zero is '-',
5662or one invoked with the '--login' option.
5663
5664 An _interactive_ shell is one started without non-option arguments,
5665unless '-s' is specified, without specifying the '-c' option, and whose
5666input and output are both connected to terminals (as determined by
5667'isatty(3)'), or one started with the '-i' option. *Note Interactive
5668Shells::, for more information.
5669
5670 If arguments remain after option processing, and neither the '-c' nor
5671the '-s' option has been supplied, the first argument is assumed to be
5672the name of a file containing shell commands (*note Shell Scripts::).
5673When Bash is invoked in this fashion, '$0' is set to the name of the
5674file, and the positional parameters are set to the remaining arguments.
5675Bash reads and executes commands from this file, then exits. Bash's
5676exit status is the exit status of the last command executed in the
5677script. If no commands are executed, the exit status is 0.
5678
5679\1f
5680File: bash.info, Node: Bash Startup Files, Next: Interactive Shells, Prev: Invoking Bash, Up: Bash Features
5681
56826.2 Bash Startup Files
5683======================
5684
5685This section describes how Bash executes its startup files. If any of
5686the files exist but cannot be read, Bash reports an error. Tildes are
5687expanded in filenames as described above under Tilde Expansion (*note
5688Tilde Expansion::).
5689
5690 Interactive shells are described in *note Interactive Shells::.
5691
5692Invoked as an interactive login shell, or with '--login'
5693........................................................
5694
5695When Bash is invoked as an interactive login shell, or as a
5696non-interactive shell with the '--login' option, it first reads and
5697executes commands from the file '/etc/profile', if that file exists.
5698After reading that file, it looks for '~/.bash_profile',
5699'~/.bash_login', and '~/.profile', in that order, and reads and executes
5700commands from the first one that exists and is readable. The
5701'--noprofile' option may be used when the shell is started to inhibit
5702this behavior.
5703
5704 When an interactive login shell exits, or a non-interactive login
5705shell executes the 'exit' builtin command, Bash reads and executes
5706commands from the file '~/.bash_logout', if it exists.
5707
5708Invoked as an interactive non-login shell
5709.........................................
5710
5711When an interactive shell that is not a login shell is started, Bash
5712reads and executes commands from '~/.bashrc', if that file exists. This
5713may be inhibited by using the '--norc' option. The '--rcfile FILE'
5714option will force Bash to read and execute commands from FILE instead of
5715'~/.bashrc'.
5716
5717 So, typically, your '~/.bash_profile' contains the line
5718 if [ -f ~/.bashrc ]; then . ~/.bashrc; fi
5719after (or before) any login-specific initializations.
5720
5721Invoked non-interactively
5722.........................
5723
5724When Bash is started non-interactively, to run a shell script, for
5725example, it looks for the variable 'BASH_ENV' in the environment,
5726expands its value if it appears there, and uses the expanded value as
5727the name of a file to read and execute. Bash behaves as if the
5728following command were executed:
5729 if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
5730but the value of the 'PATH' variable is not used to search for the
5731filename.
5732
5733 As noted above, if a non-interactive shell is invoked with the
5734'--login' option, Bash attempts to read and execute commands from the
5735login shell startup files.
5736
5737Invoked with name 'sh'
5738......................
5739
5740If Bash is invoked with the name 'sh', it tries to mimic the startup
5741behavior of historical versions of 'sh' as closely as possible, while
5742conforming to the POSIX standard as well.
5743
5744 When invoked as an interactive login shell, or as a non-interactive
5745shell with the '--login' option, it first attempts to read and execute
5746commands from '/etc/profile' and '~/.profile', in that order. The
5747'--noprofile' option may be used to inhibit this behavior. When invoked
5748as an interactive shell with the name 'sh', Bash looks for the variable
5749'ENV', expands its value if it is defined, and uses the expanded value
5750as the name of a file to read and execute. Since a shell invoked as
5751'sh' does not attempt to read and execute commands from any other
5752startup files, the '--rcfile' option has no effect. A non-interactive
5753shell invoked with the name 'sh' does not attempt to read any other
5754startup files.
5755
5756 When invoked as 'sh', Bash enters POSIX mode after the startup files
5757are read.
5758
5759Invoked in POSIX mode
5760.....................
5761
5762When Bash is started in POSIX mode, as with the '--posix' command line
5763option, it follows the POSIX standard for startup files. In this mode,
5764interactive shells expand the 'ENV' variable and commands are read and
5765executed from the file whose name is the expanded value. No other
5766startup files are read.
5767
5768Invoked by remote shell daemon
5769..............................
5770
5771Bash attempts to determine when it is being run with its standard input
5772connected to a network connection, as when executed by the remote shell
5773daemon, usually 'rshd', or the secure shell daemon 'sshd'. If Bash
5774determines it is being run in this fashion, it reads and executes
5775commands from '~/.bashrc', if that file exists and is readable. It will
5776not do this if invoked as 'sh'. The '--norc' option may be used to
5777inhibit this behavior, and the '--rcfile' option may be used to force
5778another file to be read, but neither 'rshd' nor 'sshd' generally invoke
5779the shell with those options or allow them to be specified.
5780
5781Invoked with unequal effective and real UID/GIDs
5782................................................
5783
5784If Bash is started with the effective user (group) id not equal to the
5785real user (group) id, and the '-p' option is not supplied, no startup
5786files are read, shell functions are not inherited from the environment,
5787the 'SHELLOPTS', 'BASHOPTS', 'CDPATH', and 'GLOBIGNORE' variables, if
5788they appear in the environment, are ignored, and the effective user id
5789is set to the real user id. If the '-p' option is supplied at
5790invocation, the startup behavior is the same, but the effective user id
5791is not reset.
5792
5793\1f
5794File: bash.info, Node: Interactive Shells, Next: Bash Conditional Expressions, Prev: Bash Startup Files, Up: Bash Features
5795
57966.3 Interactive Shells
5797======================
5798
5799* Menu:
5800
5801* What is an Interactive Shell?:: What determines whether a shell is Interactive.
5802* Is this Shell Interactive?:: How to tell if a shell is interactive.
5803* Interactive Shell Behavior:: What changes in a interactive shell?
5804
5805\1f
5806File: bash.info, Node: What is an Interactive Shell?, Next: Is this Shell Interactive?, Up: Interactive Shells
5807
58086.3.1 What is an Interactive Shell?
5809-----------------------------------
5810
5811An interactive shell is one started without non-option arguments, unless
5812'-s' is specified, without specifying the '-c' option, and whose input
5813and error output are both connected to terminals (as determined by
5814'isatty(3)'), or one started with the '-i' option.
5815
5816 An interactive shell generally reads from and writes to a user's
5817terminal.
5818
5819 The '-s' invocation option may be used to set the positional
5820parameters when an interactive shell is started.
5821
5822\1f
5823File: bash.info, Node: Is this Shell Interactive?, Next: Interactive Shell Behavior, Prev: What is an Interactive Shell?, Up: Interactive Shells
5824
58256.3.2 Is this Shell Interactive?
5826--------------------------------
5827
5828To determine within a startup script whether or not Bash is running
5829interactively, test the value of the '-' special parameter. It contains
5830'i' when the shell is interactive. For example:
5831
5832 case "$-" in
5833 *i*) echo This shell is interactive ;;
5834 *) echo This shell is not interactive ;;
5835 esac
5836
5837 Alternatively, startup scripts may examine the variable 'PS1'; it is
5838unset in non-interactive shells, and set in interactive shells. Thus:
5839
5840 if [ -z "$PS1" ]; then
5841 echo This shell is not interactive
5842 else
5843 echo This shell is interactive
5844 fi
5845
5846\1f
5847File: bash.info, Node: Interactive Shell Behavior, Prev: Is this Shell Interactive?, Up: Interactive Shells
5848
58496.3.3 Interactive Shell Behavior
5850--------------------------------
5851
5852When the shell is running interactively, it changes its behavior in
5853several ways.
5854
5855 1. Startup files are read and executed as described in *note Bash
5856 Startup Files::.
5857
5858 2. Job Control (*note Job Control::) is enabled by default. When job
5859 control is in effect, Bash ignores the keyboard-generated job
5860 control signals 'SIGTTIN', 'SIGTTOU', and 'SIGTSTP'.
5861
5862 3. Bash expands and displays 'PS1' before reading the first line of a
5863 command, and expands and displays 'PS2' before reading the second
d233b485
CR
5864 and subsequent lines of a multi-line command. Bash expands and
5865 displays 'PS0' after it reads a command but before executing it.
5866 See *note Controlling the Prompt::, for a complete list of prompt
5867 string escape sequences.
a0c0a00f
CR
5868
5869 4. Bash executes the value of the 'PROMPT_COMMAND' variable as a
5870 command before printing the primary prompt, '$PS1' (*note Bash
5871 Variables::).
5872
5873 5. Readline (*note Command Line Editing::) is used to read commands
5874 from the user's terminal.
5875
5876 6. Bash inspects the value of the 'ignoreeof' option to 'set -o'
5877 instead of exiting immediately when it receives an 'EOF' on its
5878 standard input when reading a command (*note The Set Builtin::).
5879
5880 7. Command history (*note Bash History Facilities::) and history
5881 expansion (*note History Interaction::) are enabled by default.
5882 Bash will save the command history to the file named by '$HISTFILE'
5883 when a shell with history enabled exits.
5884
5885 8. Alias expansion (*note Aliases::) is performed by default.
5886
5887 9. In the absence of any traps, Bash ignores 'SIGTERM' (*note
5888 Signals::).
5889
d233b485
CR
5890 10. In the absence of any traps, 'SIGINT' is caught and handled (*note
5891 Signals::). 'SIGINT' will interrupt some shell builtins.
a0c0a00f
CR
5892
5893 11. An interactive login shell sends a 'SIGHUP' to all jobs on exit if
5894 the 'huponexit' shell option has been enabled (*note Signals::).
5895
5896 12. The '-n' invocation option is ignored, and 'set -n' has no effect
5897 (*note The Set Builtin::).
5898
5899 13. Bash will check for mail periodically, depending on the values of
5900 the 'MAIL', 'MAILPATH', and 'MAILCHECK' shell variables (*note Bash
5901 Variables::).
5902
5903 14. Expansion errors due to references to unbound shell variables
5904 after 'set -u' has been enabled will not cause the shell to exit
5905 (*note The Set Builtin::).
5906
5907 15. The shell will not exit on expansion errors caused by VAR being
5908 unset or null in '${VAR:?WORD}' expansions (*note Shell Parameter
5909 Expansion::).
5910
5911 16. Redirection errors encountered by shell builtins will not cause
5912 the shell to exit.
5913
5914 17. When running in POSIX mode, a special builtin returning an error
5915 status will not cause the shell to exit (*note Bash POSIX Mode::).
5916
5917 18. A failed 'exec' will not cause the shell to exit (*note Bourne
5918 Shell Builtins::).
5919
5920 19. Parser syntax errors will not cause the shell to exit.
5921
5922 20. Simple spelling correction for directory arguments to the 'cd'
5923 builtin is enabled by default (see the description of the 'cdspell'
5924 option to the 'shopt' builtin in *note The Shopt Builtin::).
5925
5926 21. The shell will check the value of the 'TMOUT' variable and exit if
5927 a command is not read within the specified number of seconds after
5928 printing '$PS1' (*note Bash Variables::).
5929
5930\1f
5931File: bash.info, Node: Bash Conditional Expressions, Next: Shell Arithmetic, Prev: Interactive Shells, Up: Bash Features
5932
59336.4 Bash Conditional Expressions
5934================================
5935
5936Conditional expressions are used by the '[[' compound command and the
d233b485
CR
5937'test' and '[' builtin commands. The 'test' and '[' commands determine
5938their behavior based on the number of arguments; see the descriptions of
5939those commands for any other command-specific actions.
5940
5941 Expressions may be unary or binary, and are formed from the following
5942primaries. Unary expressions are often used to examine the status of a
5943file. There are string operators and numeric comparison operators as
5944well. Bash handles several filenames specially when they are used in
5945expressions. If the operating system on which Bash is running provides
5946these special files, Bash will use them; otherwise it will emulate them
5947internally with this behavior: If the FILE argument to one of the
5948primaries is of the form '/dev/fd/N', then file descriptor N is checked.
5949If the FILE argument to one of the primaries is one of '/dev/stdin',
5950'/dev/stdout', or '/dev/stderr', file descriptor 0, 1, or 2,
5951respectively, is checked.
a0c0a00f
CR
5952
5953 When used with '[[', the '<' and '>' operators sort lexicographically
5954using the current locale. The 'test' command uses ASCII ordering.
5955
5956 Unless otherwise specified, primaries that operate on files follow
5957symbolic links and operate on the target of the link, rather than the
5958link itself.
5959
5960'-a FILE'
5961 True if FILE exists.
5962
5963'-b FILE'
5964 True if FILE exists and is a block special file.
5965
5966'-c FILE'
5967 True if FILE exists and is a character special file.
5968
5969'-d FILE'
5970 True if FILE exists and is a directory.
5971
5972'-e FILE'
5973 True if FILE exists.
5974
5975'-f FILE'
5976 True if FILE exists and is a regular file.
5977
5978'-g FILE'
5979 True if FILE exists and its set-group-id bit is set.
5980
5981'-h FILE'
5982 True if FILE exists and is a symbolic link.
5983
5984'-k FILE'
5985 True if FILE exists and its "sticky" bit is set.
5986
5987'-p FILE'
5988 True if FILE exists and is a named pipe (FIFO).
5989
5990'-r FILE'
5991 True if FILE exists and is readable.
5992
5993'-s FILE'
5994 True if FILE exists and has a size greater than zero.
5995
5996'-t FD'
5997 True if file descriptor FD is open and refers to a terminal.
5998
5999'-u FILE'
6000 True if FILE exists and its set-user-id bit is set.
6001
6002'-w FILE'
6003 True if FILE exists and is writable.
6004
6005'-x FILE'
6006 True if FILE exists and is executable.
6007
6008'-G FILE'
6009 True if FILE exists and is owned by the effective group id.
6010
6011'-L FILE'
6012 True if FILE exists and is a symbolic link.
6013
6014'-N FILE'
6015 True if FILE exists and has been modified since it was last read.
6016
6017'-O FILE'
6018 True if FILE exists and is owned by the effective user id.
6019
6020'-S FILE'
6021 True if FILE exists and is a socket.
6022
6023'FILE1 -ef FILE2'
6024 True if FILE1 and FILE2 refer to the same device and inode numbers.
6025
6026'FILE1 -nt FILE2'
6027 True if FILE1 is newer (according to modification date) than FILE2,
6028 or if FILE1 exists and FILE2 does not.
6029
6030'FILE1 -ot FILE2'
6031 True if FILE1 is older than FILE2, or if FILE2 exists and FILE1
6032 does not.
6033
6034'-o OPTNAME'
6035 True if the shell option OPTNAME is enabled. The list of options
6036 appears in the description of the '-o' option to the 'set' builtin
6037 (*note The Set Builtin::).
6038
6039'-v VARNAME'
6040 True if the shell variable VARNAME is set (has been assigned a
6041 value).
6042
6043'-R VARNAME'
6044 True if the shell variable VARNAME is set and is a name reference.
6045
6046'-z STRING'
6047 True if the length of STRING is zero.
6048
6049'-n STRING'
6050'STRING'
6051 True if the length of STRING is non-zero.
6052
6053'STRING1 == STRING2'
6054'STRING1 = STRING2'
6055 True if the strings are equal. When used with the '[[' command,
6056 this performs pattern matching as described above (*note
6057 Conditional Constructs::).
6058
6059 '=' should be used with the 'test' command for POSIX conformance.
6060
6061'STRING1 != STRING2'
6062 True if the strings are not equal.
6063
6064'STRING1 < STRING2'
6065 True if STRING1 sorts before STRING2 lexicographically.
6066
6067'STRING1 > STRING2'
6068 True if STRING1 sorts after STRING2 lexicographically.
6069
6070'ARG1 OP ARG2'
6071 'OP' is one of '-eq', '-ne', '-lt', '-le', '-gt', or '-ge'. These
6072 arithmetic binary operators return true if ARG1 is equal to, not
6073 equal to, less than, less than or equal to, greater than, or
6074 greater than or equal to ARG2, respectively. ARG1 and ARG2 may be
d233b485
CR
6075 positive or negative integers. When used with the '[[' command,
6076 ARG1 and ARG2 are evaluated as arithmetic expressions (*note Shell
6077 Arithmetic::).
a0c0a00f
CR
6078
6079\1f
6080File: bash.info, Node: Shell Arithmetic, Next: Aliases, Prev: Bash Conditional Expressions, Up: Bash Features
6081
60826.5 Shell Arithmetic
6083====================
6084
6085The shell allows arithmetic expressions to be evaluated, as one of the
6086shell expansions or by using the '((' compound command, the 'let'
6087builtin, or the '-i' option to the 'declare' builtin.
6088
6089 Evaluation is done in fixed-width integers with no check for
6090overflow, though division by 0 is trapped and flagged as an error. The
6091operators and their precedence, associativity, and values are the same
6092as in the C language. The following list of operators is grouped into
6093levels of equal-precedence operators. The levels are listed in order of
6094decreasing precedence.
6095
6096'ID++ ID--'
6097 variable post-increment and post-decrement
6098
6099'++ID --ID'
6100 variable pre-increment and pre-decrement
6101
6102'- +'
6103 unary minus and plus
6104
6105'! ~'
6106 logical and bitwise negation
6107
6108'**'
6109 exponentiation
6110
6111'* / %'
6112 multiplication, division, remainder
6113
6114'+ -'
6115 addition, subtraction
6116
6117'<< >>'
6118 left and right bitwise shifts
6119
6120'<= >= < >'
6121 comparison
6122
6123'== !='
6124 equality and inequality
6125
6126'&'
6127 bitwise AND
6128
6129'^'
6130 bitwise exclusive OR
6131
6132'|'
6133 bitwise OR
6134
6135'&&'
6136 logical AND
6137
6138'||'
6139 logical OR
6140
6141'expr ? expr : expr'
6142 conditional operator
6143
6144'= *= /= %= += -= <<= >>= &= ^= |='
6145 assignment
6146
6147'expr1 , expr2'
6148 comma
6149
6150 Shell variables are allowed as operands; parameter expansion is
6151performed before the expression is evaluated. Within an expression,
6152shell variables may also be referenced by name without using the
6153parameter expansion syntax. A shell variable that is null or unset
6154evaluates to 0 when referenced by name without using the parameter
6155expansion syntax. The value of a variable is evaluated as an arithmetic
6156expression when it is referenced, or when a variable which has been
6157given the INTEGER attribute using 'declare -i' is assigned a value. A
6158null value evaluates to 0. A shell variable need not have its INTEGER
6159attribute turned on to be used in an expression.
6160
6161 Constants with a leading 0 are interpreted as octal numbers. A
6162leading '0x' or '0X' denotes hexadecimal. Otherwise, numbers take the
6163form [BASE'#']N, where the optional BASE is a decimal number between 2
6164and 64 representing the arithmetic base, and N is a number in that base.
6165If BASE'#' is omitted, then base 10 is used. When specifying N, the
6166digits greater than 9 are represented by the lowercase letters, the
6167uppercase letters, '@', and '_', in that order. If BASE is less than or
6168equal to 36, lowercase and uppercase letters may be used interchangeably
6169to represent numbers between 10 and 35.
6170
6171 Operators are evaluated in order of precedence. Sub-expressions in
6172parentheses are evaluated first and may override the precedence rules
6173above.
6174
6175\1f
6176File: bash.info, Node: Aliases, Next: Arrays, Prev: Shell Arithmetic, Up: Bash Features
6177
61786.6 Aliases
6179===========
6180
6181ALIASES allow a string to be substituted for a word when it is used as
6182the first word of a simple command. The shell maintains a list of
6183aliases that may be set and unset with the 'alias' and 'unalias' builtin
6184commands.
6185
6186 The first word of each simple command, if unquoted, is checked to see
6187if it has an alias. If so, that word is replaced by the text of the
6188alias. The characters '/', '$', '`', '=' and any of the shell
6189metacharacters or quoting characters listed above may not appear in an
6190alias name. The replacement text may contain any valid shell input,
6191including shell metacharacters. The first word of the replacement text
6192is tested for aliases, but a word that is identical to an alias being
6193expanded is not expanded a second time. This means that one may alias
6194'ls' to '"ls -F"', for instance, and Bash does not try to recursively
6195expand the replacement text. If the last character of the alias value
6196is a BLANK, then the next command word following the alias is also
6197checked for alias expansion.
6198
6199 Aliases are created and listed with the 'alias' command, and removed
6200with the 'unalias' command.
6201
6202 There is no mechanism for using arguments in the replacement text, as
6203in 'csh'. If arguments are needed, a shell function should be used
6204(*note Shell Functions::).
6205
6206 Aliases are not expanded when the shell is not interactive, unless
6207the 'expand_aliases' shell option is set using 'shopt' (*note The Shopt
6208Builtin::).
6209
6210 The rules concerning the definition and use of aliases are somewhat
d233b485
CR
6211confusing. Bash always reads at least one complete line of input, and
6212all lines that make up a compound command, before executing any of the
6213commands on that line or the compound command. Aliases are expanded
6214when a command is read, not when it is executed. Therefore, an alias
a0c0a00f
CR
6215definition appearing on the same line as another command does not take
6216effect until the next line of input is read. The commands following the
6217alias definition on that line are not affected by the new alias. This
6218behavior is also an issue when functions are executed. Aliases are
6219expanded when a function definition is read, not when the function is
6220executed, because a function definition is itself a command. As a
6221consequence, aliases defined in a function are not available until after
6222that function is executed. To be safe, always put alias definitions on
6223a separate line, and do not use 'alias' in compound commands.
6224
6225 For almost every purpose, shell functions are preferred over aliases.
6226
6227\1f
6228File: bash.info, Node: Arrays, Next: The Directory Stack, Prev: Aliases, Up: Bash Features
6229
62306.7 Arrays
6231==========
6232
6233Bash provides one-dimensional indexed and associative array variables.
6234Any variable may be used as an indexed array; the 'declare' builtin will
6235explicitly declare an array. There is no maximum limit on the size of
6236an array, nor any requirement that members be indexed or assigned
6237contiguously. Indexed arrays are referenced using integers (including
6238arithmetic expressions (*note Shell Arithmetic::)) and are zero-based;
6239associative arrays use arbitrary strings. Unless otherwise noted,
6240indexed array indices must be non-negative integers.
6241
6242 An indexed array is created automatically if any variable is assigned
6243to using the syntax
6244 NAME[SUBSCRIPT]=VALUE
6245
6246The SUBSCRIPT is treated as an arithmetic expression that must evaluate
6247to a number. To explicitly declare an array, use
6248 declare -a NAME
6249The syntax
6250 declare -a NAME[SUBSCRIPT]
6251is also accepted; the SUBSCRIPT is ignored.
6252
6253Associative arrays are created using
6254 declare -A NAME.
6255
6256 Attributes may be specified for an array variable using the 'declare'
6257and 'readonly' builtins. Each attribute applies to all members of an
6258array.
6259
6260 Arrays are assigned to using compound assignments of the form
6261 NAME=(VALUE1 VALUE2 ... )
6262where each VALUE is of the form '[SUBSCRIPT]='STRING. Indexed array
6263assignments do not require anything but STRING. When assigning to
6264indexed arrays, if the optional subscript is supplied, that index is
6265assigned to; otherwise the index of the element assigned is the last
6266index assigned to by the statement plus one. Indexing starts at zero.
6267
6268 When assigning to an associative array, the subscript is required.
6269
6270 This syntax is also accepted by the 'declare' builtin. Individual
6271array elements may be assigned to using the 'NAME[SUBSCRIPT]=VALUE'
6272syntax introduced above.
6273
6274 When assigning to an indexed array, if NAME is subscripted by a
6275negative number, that number is interpreted as relative to one greater
6276than the maximum index of NAME, so negative indices count back from the
6277end of the array, and an index of -1 references the last element.
6278
6279 Any element of an array may be referenced using '${NAME[SUBSCRIPT]}'.
6280The braces are required to avoid conflicts with the shell's filename
6281expansion operators. If the SUBSCRIPT is '@' or '*', the word expands
6282to all members of the array NAME. These subscripts differ only when the
6283word appears within double quotes. If the word is double-quoted,
6284'${NAME[*]}' expands to a single word with the value of each array
6285member separated by the first character of the 'IFS' variable, and
6286'${NAME[@]}' expands each element of NAME to a separate word. When
6287there are no array members, '${NAME[@]}' expands to nothing. If the
6288double-quoted expansion occurs within a word, the expansion of the first
6289parameter is joined with the beginning part of the original word, and
6290the expansion of the last parameter is joined with the last part of the
6291original word. This is analogous to the expansion of the special
6292parameters '@' and '*'. '${#NAME[SUBSCRIPT]}' expands to the length of
6293'${NAME[SUBSCRIPT]}'. If SUBSCRIPT is '@' or '*', the expansion is the
6294number of elements in the array. If the SUBSCRIPT used to reference an
6295element of an indexed array evaluates to a number less than zero, it is
6296interpreted as relative to one greater than the maximum index of the
6297array, so negative indices count back from the end of the array, and an
6298index of -1 refers to the last element.
6299
6300 Referencing an array variable without a subscript is equivalent to
6301referencing with a subscript of 0. Any reference to a variable using a
6302valid subscript is legal, and 'bash' will create an array if necessary.
6303
6304 An array variable is considered set if a subscript has been assigned
6305a value. The null string is a valid value.
6306
6307 It is possible to obtain the keys (indices) of an array as well as
6308the values. ${!NAME[@]} and ${!NAME[*]} expand to the indices assigned
6309in array variable NAME. The treatment when in double quotes is similar
6310to the expansion of the special parameters '@' and '*' within double
6311quotes.
6312
6313 The 'unset' builtin is used to destroy arrays. 'unset
6314NAME[SUBSCRIPT]' destroys the array element at index SUBSCRIPT.
6315Negative subscripts to indexed arrays are interpreted as described
d233b485
CR
6316above. Unsetting the last element of an array variable does not unset
6317the variable. 'unset NAME', where NAME is an array, removes the entire
6318array. A subscript of '*' or '@' also removes the entire array.
6319
6320 When using a variable name with a subscript as an argument to a
6321command, such as with 'unset', without using the word expansion syntax
6322described above, the argument is subject to the shell's filename
6323expansion. If filename expansion is not desired, the argument should be
6324quoted.
a0c0a00f
CR
6325
6326 The 'declare', 'local', and 'readonly' builtins each accept a '-a'
6327option to specify an indexed array and a '-A' option to specify an
6328associative array. If both options are supplied, '-A' takes precedence.
6329The 'read' builtin accepts a '-a' option to assign a list of words read
6330from the standard input to an array, and can read values from the
6331standard input into individual array elements. The 'set' and 'declare'
6332builtins display array values in a way that allows them to be reused as
6333input.
6334
6335\1f
6336File: bash.info, Node: The Directory Stack, Next: Controlling the Prompt, Prev: Arrays, Up: Bash Features
6337
63386.8 The Directory Stack
6339=======================
6340
6341* Menu:
6342
6343* Directory Stack Builtins:: Bash builtin commands to manipulate
6344 the directory stack.
6345
6346The directory stack is a list of recently-visited directories. The
6347'pushd' builtin adds directories to the stack as it changes the current
6348directory, and the 'popd' builtin removes specified directories from the
6349stack and changes the current directory to the directory removed. The
6350'dirs' builtin displays the contents of the directory stack. The
6351current directory is always the "top" of the directory stack.
6352
6353 The contents of the directory stack are also visible as the value of
6354the 'DIRSTACK' shell variable.
6355
6356\1f
6357File: bash.info, Node: Directory Stack Builtins, Up: The Directory Stack
6358
63596.8.1 Directory Stack Builtins
6360------------------------------
6361
6362'dirs'
6363 dirs [-clpv] [+N | -N]
6364
6365 Display the list of currently remembered directories. Directories
6366 are added to the list with the 'pushd' command; the 'popd' command
6367 removes directories from the list. The current directory is always
6368 the first directory in the stack.
6369
6370 '-c'
6371 Clears the directory stack by deleting all of the elements.
6372 '-l'
6373 Produces a listing using full pathnames; the default listing
6374 format uses a tilde to denote the home directory.
6375 '-p'
6376 Causes 'dirs' to print the directory stack with one entry per
6377 line.
6378 '-v'
6379 Causes 'dirs' to print the directory stack with one entry per
6380 line, prefixing each entry with its index in the stack.
6381 '+N'
6382 Displays the Nth directory (counting from the left of the list
6383 printed by 'dirs' when invoked without options), starting with
6384 zero.
6385 '-N'
6386 Displays the Nth directory (counting from the right of the
6387 list printed by 'dirs' when invoked without options), starting
6388 with zero.
6389
6390'popd'
6391 popd [-n] [+N | -N]
6392
6393 When no arguments are given, 'popd' removes the top directory from
6394 the stack and performs a 'cd' to the new top directory. The
6395 elements are numbered from 0 starting at the first directory listed
6396 with 'dirs'; that is, 'popd' is equivalent to 'popd +0'.
6397
6398 '-n'
6399 Suppresses the normal change of directory when removing
6400 directories from the stack, so that only the stack is
6401 manipulated.
6402 '+N'
6403 Removes the Nth directory (counting from the left of the list
6404 printed by 'dirs'), starting with zero.
6405 '-N'
6406 Removes the Nth directory (counting from the right of the list
6407 printed by 'dirs'), starting with zero.
6408
6409'pushd'
6410 pushd [-n] [+N | -N | DIR]
6411
6412 Save the current directory on the top of the directory stack and
6413 then 'cd' to DIR. With no arguments, 'pushd' exchanges the top two
6414 directories and makes the new top the current directory.
6415
6416 '-n'
6417 Suppresses the normal change of directory when rotating or
6418 adding directories to the stack, so that only the stack is
6419 manipulated.
6420 '+N'
6421 Brings the Nth directory (counting from the left of the list
6422 printed by 'dirs', starting with zero) to the top of the list
6423 by rotating the stack.
6424 '-N'
6425 Brings the Nth directory (counting from the right of the list
6426 printed by 'dirs', starting with zero) to the top of the list
6427 by rotating the stack.
6428 'DIR'
6429 Makes DIR be the top of the stack, making it the new current
6430 directory as if it had been supplied as an argument to the
6431 'cd' builtin.
6432
6433\1f
6434File: bash.info, Node: Controlling the Prompt, Next: The Restricted Shell, Prev: The Directory Stack, Up: Bash Features
6435
64366.9 Controlling the Prompt
6437==========================
6438
6439The value of the variable 'PROMPT_COMMAND' is examined just before Bash
6440prints each primary prompt. If 'PROMPT_COMMAND' is set and has a
6441non-null value, then the value is executed just as if it had been typed
6442on the command line.
6443
6444 In addition, the following table describes the special characters
d233b485 6445which can appear in the prompt variables 'PS0', 'PS1', 'PS2', and 'PS4':
a0c0a00f
CR
6446
6447'\a'
6448 A bell character.
6449'\d'
6450 The date, in "Weekday Month Date" format (e.g., "Tue May 26").
6451'\D{FORMAT}'
6452 The FORMAT is passed to 'strftime'(3) and the result is inserted
6453 into the prompt string; an empty FORMAT results in a
6454 locale-specific time representation. The braces are required.
6455'\e'
6456 An escape character.
6457'\h'
6458 The hostname, up to the first '.'.
6459'\H'
6460 The hostname.
6461'\j'
6462 The number of jobs currently managed by the shell.
6463'\l'
6464 The basename of the shell's terminal device name.
6465'\n'
6466 A newline.
6467'\r'
6468 A carriage return.
6469'\s'
6470 The name of the shell, the basename of '$0' (the portion following
6471 the final slash).
6472'\t'
6473 The time, in 24-hour HH:MM:SS format.
6474'\T'
6475 The time, in 12-hour HH:MM:SS format.
6476'\@'
6477 The time, in 12-hour am/pm format.
6478'\A'
6479 The time, in 24-hour HH:MM format.
6480'\u'
6481 The username of the current user.
6482'\v'
6483 The version of Bash (e.g., 2.00)
6484'\V'
6485 The release of Bash, version + patchlevel (e.g., 2.00.0)
6486'\w'
6487 The current working directory, with '$HOME' abbreviated with a
6488 tilde (uses the '$PROMPT_DIRTRIM' variable).
6489'\W'
6490 The basename of '$PWD', with '$HOME' abbreviated with a tilde.
6491'\!'
6492 The history number of this command.
6493'\#'
6494 The command number of this command.
6495'\$'
6496 If the effective uid is 0, '#', otherwise '$'.
6497'\NNN'
6498 The character whose ASCII code is the octal value NNN.
6499'\\'
6500 A backslash.
6501'\['
6502 Begin a sequence of non-printing characters. This could be used to
6503 embed a terminal control sequence into the prompt.
6504'\]'
6505 End a sequence of non-printing characters.
6506
6507 The command number and the history number are usually different: the
6508history number of a command is its position in the history list, which
6509may include commands restored from the history file (*note Bash History
6510Facilities::), while the command number is the position in the sequence
6511of commands executed during the current shell session.
6512
6513 After the string is decoded, it is expanded via parameter expansion,
6514command substitution, arithmetic expansion, and quote removal, subject
d233b485
CR
6515to the value of the 'promptvars' shell option (*note The Shopt
6516Builtin::).
a0c0a00f
CR
6517
6518\1f
6519File: bash.info, Node: The Restricted Shell, Next: Bash POSIX Mode, Prev: Controlling the Prompt, Up: Bash Features
6520
65216.10 The Restricted Shell
6522=========================
6523
6524If Bash is started with the name 'rbash', or the '--restricted' or '-r'
6525option is supplied at invocation, the shell becomes restricted. A
6526restricted shell is used to set up an environment more controlled than
6527the standard shell. A restricted shell behaves identically to 'bash'
6528with the exception that the following are disallowed or not performed:
6529
6530 * Changing directories with the 'cd' builtin.
6531 * Setting or unsetting the values of the 'SHELL', 'PATH', 'ENV', or
6532 'BASH_ENV' variables.
6533 * Specifying command names containing slashes.
6534 * Specifying a filename containing a slash as an argument to the '.'
6535 builtin command.
6536 * Specifying a filename containing a slash as an argument to the '-p'
6537 option to the 'hash' builtin command.
6538 * Importing function definitions from the shell environment at
6539 startup.
6540 * Parsing the value of 'SHELLOPTS' from the shell environment at
6541 startup.
6542 * Redirecting output using the '>', '>|', '<>', '>&', '&>', and '>>'
6543 redirection operators.
6544 * Using the 'exec' builtin to replace the shell with another command.
6545 * Adding or deleting builtin commands with the '-f' and '-d' options
6546 to the 'enable' builtin.
6547 * Using the 'enable' builtin command to enable disabled shell
6548 builtins.
6549 * Specifying the '-p' option to the 'command' builtin.
6550 * Turning off restricted mode with 'set +r' or 'set +o restricted'.
6551
6552 These restrictions are enforced after any startup files are read.
6553
6554 When a command that is found to be a shell script is executed (*note
6555Shell Scripts::), 'rbash' turns off any restrictions in the shell
6556spawned to execute the script.
6557
6558\1f
6559File: bash.info, Node: Bash POSIX Mode, Prev: The Restricted Shell, Up: Bash Features
6560
65616.11 Bash POSIX Mode
6562====================
6563
6564Starting Bash with the '--posix' command-line option or executing 'set
6565-o posix' while Bash is running will cause Bash to conform more closely
6566to the POSIX standard by changing the behavior to match that specified
6567by POSIX in areas where the Bash default differs.
6568
6569 When invoked as 'sh', Bash enters POSIX mode after reading the
6570startup files.
6571
6572 The following list is what's changed when 'POSIX mode' is in effect:
6573
d233b485
CR
6574 1. Bash ensures that the 'POSIXLY_CORRECT' variable is set.
6575
6576 2. When a command in the hash table no longer exists, Bash will
a0c0a00f
CR
6577 re-search '$PATH' to find the new location. This is also available
6578 with 'shopt -s checkhash'.
6579
d233b485 6580 3. The message printed by the job control code and builtins when a job
a0c0a00f
CR
6581 exits with a non-zero status is 'Done(status)'.
6582
d233b485 6583 4. The message printed by the job control code and builtins when a job
a0c0a00f
CR
6584 is stopped is 'Stopped(SIGNAME)', where SIGNAME is, for example,
6585 'SIGTSTP'.
6586
d233b485 6587 5. Alias expansion is always enabled, even in non-interactive shells.
a0c0a00f 6588
d233b485 6589 6. Reserved words appearing in a context where reserved words are
a0c0a00f
CR
6590 recognized do not undergo alias expansion.
6591
d233b485 6592 7. The POSIX 'PS1' and 'PS2' expansions of '!' to the history number
a0c0a00f
CR
6593 and '!!' to '!' are enabled, and parameter expansion is performed
6594 on the values of 'PS1' and 'PS2' regardless of the setting of the
6595 'promptvars' option.
6596
d233b485 6597 8. The POSIX startup files are executed ('$ENV') rather than the
a0c0a00f
CR
6598 normal Bash files.
6599
d233b485 6600 9. Tilde expansion is only performed on assignments preceding a
a0c0a00f
CR
6601 command name, rather than on all assignment statements on the line.
6602
d233b485 6603 10. The default history file is '~/.sh_history' (this is the default
a0c0a00f
CR
6604 value of '$HISTFILE').
6605
d233b485 6606 11. Redirection operators do not perform filename expansion on the
a0c0a00f
CR
6607 word in the redirection unless the shell is interactive.
6608
d233b485 6609 12. Redirection operators do not perform word splitting on the word in
a0c0a00f
CR
6610 the redirection.
6611
d233b485 6612 13. Function names must be valid shell 'name's. That is, they may not
a0c0a00f
CR
6613 contain characters other than letters, digits, and underscores, and
6614 may not start with a digit. Declaring a function with an invalid
6615 name causes a fatal syntax error in non-interactive shells.
6616
d233b485 6617 14. Function names may not be the same as one of the POSIX special
a0c0a00f
CR
6618 builtins.
6619
d233b485 6620 15. POSIX special builtins are found before shell functions during
a0c0a00f
CR
6621 command lookup.
6622
d233b485 6623 16. When printing shell function definitions (e.g., by 'type'), Bash
a0c0a00f
CR
6624 does not print the 'function' keyword.
6625
d233b485 6626 17. Literal tildes that appear as the first character in elements of
a0c0a00f
CR
6627 the 'PATH' variable are not expanded as described above under *note
6628 Tilde Expansion::.
6629
d233b485 6630 18. The 'time' reserved word may be used by itself as a command. When
a0c0a00f
CR
6631 used in this way, it displays timing statistics for the shell and
6632 its completed children. The 'TIMEFORMAT' variable controls the
6633 format of the timing information.
6634
d233b485 6635 19. When parsing and expanding a ${...} expansion that appears within
a0c0a00f
CR
6636 double quotes, single quotes are no longer special and cannot be
6637 used to quote a closing brace or other special character, unless
6638 the operator is one of those defined to perform pattern removal.
6639 In this case, they do not have to appear as matched pairs.
6640
d233b485 6641 20. The parser does not recognize 'time' as a reserved word if the
a0c0a00f
CR
6642 next token begins with a '-'.
6643
d233b485 6644 21. The '!' character does not introduce history expansion within a
a0c0a00f
CR
6645 double-quoted string, even if the 'histexpand' option is enabled.
6646
d233b485 6647 22. If a POSIX special builtin returns an error status, a
a0c0a00f
CR
6648 non-interactive shell exits. The fatal errors are those listed in
6649 the POSIX standard, and include things like passing incorrect
6650 options, redirection errors, variable assignment errors for
6651 assignments preceding the command name, and so on.
6652
d233b485 6653 23. A non-interactive shell exits with an error status if a variable
a0c0a00f
CR
6654 assignment error occurs when no command name follows the assignment
6655 statements. A variable assignment error occurs, for example, when
6656 trying to assign a value to a readonly variable.
6657
d233b485 6658 24. A non-interactive shell exits with an error status if a variable
a0c0a00f
CR
6659 assignment error occurs in an assignment statement preceding a
6660 special builtin, but not with any other simple command.
6661
d233b485 6662 25. A non-interactive shell exits with an error status if the
a0c0a00f
CR
6663 iteration variable in a 'for' statement or the selection variable
6664 in a 'select' statement is a readonly variable.
6665
d233b485 6666 26. Non-interactive shells exit if FILENAME in '.' FILENAME is not
a0c0a00f
CR
6667 found.
6668
d233b485 6669 27. Non-interactive shells exit if a syntax error in an arithmetic
a0c0a00f
CR
6670 expansion results in an invalid expression.
6671
d233b485 6672 28. Non-interactive shells exit if a parameter expansion error occurs.
a0c0a00f 6673
d233b485 6674 29. Non-interactive shells exit if there is a syntax error in a script
a0c0a00f
CR
6675 read with the '.' or 'source' builtins, or in a string processed by
6676 the 'eval' builtin.
6677
d233b485 6678 30. Process substitution is not available.
a0c0a00f 6679
d233b485 6680 31. While variable indirection is available, it may not be applied to
a0c0a00f
CR
6681 the '#' and '?' special parameters.
6682
d233b485 6683 32. When expanding the '*' special parameter in a pattern context
a0c0a00f
CR
6684 where the expansion is double-quoted does not treat the '$*' as if
6685 it were double-quoted.
6686
d233b485 6687 33. Assignment statements preceding POSIX special builtins persist in
a0c0a00f
CR
6688 the shell environment after the builtin completes.
6689
d233b485 6690 34. Assignment statements preceding shell function calls persist in
a0c0a00f
CR
6691 the shell environment after the function returns, as if a POSIX
6692 special builtin command had been executed.
6693
d233b485 6694 35. The 'command' builtin does not prevent builtins that take
a0c0a00f
CR
6695 assignment statements as arguments from expanding them as
6696 assignment statements; when not in POSIX mode, assignment builtins
6697 lose their assignment statement expansion properties when preceded
6698 by 'command'.
6699
d233b485 6700 36. The 'bg' builtin uses the required format to describe each job
a0c0a00f
CR
6701 placed in the background, which does not include an indication of
6702 whether the job is the current or previous job.
6703
d233b485 6704 37. The output of 'kill -l' prints all the signal names on a single
a0c0a00f
CR
6705 line, separated by spaces, without the 'SIG' prefix.
6706
d233b485 6707 38. The 'kill' builtin does not accept signal names with a 'SIG'
a0c0a00f
CR
6708 prefix.
6709
d233b485 6710 39. The 'export' and 'readonly' builtin commands display their output
a0c0a00f
CR
6711 in the format required by POSIX.
6712
d233b485 6713 40. The 'trap' builtin displays signal names without the leading
a0c0a00f
CR
6714 'SIG'.
6715
d233b485 6716 41. The 'trap' builtin doesn't check the first argument for a possible
a0c0a00f
CR
6717 signal specification and revert the signal handling to the original
6718 disposition if it is, unless that argument consists solely of
6719 digits and is a valid signal number. If users want to reset the
6720 handler for a given signal to the original disposition, they should
6721 use '-' as the first argument.
6722
d233b485 6723 42. The '.' and 'source' builtins do not search the current directory
a0c0a00f
CR
6724 for the filename argument if it is not found by searching 'PATH'.
6725
d233b485 6726 43. Enabling POSIX mode has the effect of setting the
a0c0a00f
CR
6727 'inherit_errexit' option, so subshells spawned to execute command
6728 substitutions inherit the value of the '-e' option from the parent
6729 shell. When the 'inherit_errexit' option is not enabled, Bash
6730 clears the '-e' option in such subshells.
6731
d233b485
CR
6732 44. Enabling POSIX mode has the effect of setting the 'shift_verbose'
6733 option, so numeric arguments to 'shift' that exceed the number of
6734 positional parameters will result in an error message.
6735
6736 45. When the 'alias' builtin displays alias definitions, it does not
a0c0a00f
CR
6737 display them with a leading 'alias ' unless the '-p' option is
6738 supplied.
6739
d233b485 6740 46. When the 'set' builtin is invoked without options, it does not
a0c0a00f
CR
6741 display shell function names and definitions.
6742
d233b485 6743 47. When the 'set' builtin is invoked without options, it displays
a0c0a00f
CR
6744 variable values without quotes, unless they contain shell
6745 metacharacters, even if the result contains nonprinting characters.
6746
d233b485 6747 48. When the 'cd' builtin is invoked in LOGICAL mode, and the pathname
a0c0a00f
CR
6748 constructed from '$PWD' and the directory name supplied as an
6749 argument does not refer to an existing directory, 'cd' will fail
6750 instead of falling back to PHYSICAL mode.
6751
d233b485
CR
6752 49. When the 'cd' builtin cannot change a directory because the length
6753 of the pathname constructed from '$PWD' and the directory name
6754 supplied as an argument exceeds PATH_MAX when all symbolic links
6755 are expanded, 'cd' will fail instead of attempting to use only the
6756 supplied directory name.
6757
6758 50. The 'pwd' builtin verifies that the value it prints is the same as
a0c0a00f
CR
6759 the current directory, even if it is not asked to check the file
6760 system with the '-P' option.
6761
d233b485 6762 51. When listing the history, the 'fc' builtin does not include an
a0c0a00f
CR
6763 indication of whether or not a history entry has been modified.
6764
d233b485 6765 52. The default editor used by 'fc' is 'ed'.
a0c0a00f 6766
d233b485 6767 53. The 'type' and 'command' builtins will not report a non-executable
a0c0a00f
CR
6768 file as having been found, though the shell will attempt to execute
6769 such a file if it is the only so-named file found in '$PATH'.
6770
d233b485 6771 54. The 'vi' editing mode will invoke the 'vi' editor directly when
a0c0a00f
CR
6772 the 'v' command is run, instead of checking '$VISUAL' and
6773 '$EDITOR'.
6774
d233b485 6775 55. When the 'xpg_echo' option is enabled, Bash does not attempt to
a0c0a00f
CR
6776 interpret any arguments to 'echo' as options. Each argument is
6777 displayed, after escape characters are converted.
6778
d233b485 6779 56. The 'ulimit' builtin uses a block size of 512 bytes for the '-c'
a0c0a00f
CR
6780 and '-f' options.
6781
d233b485 6782 57. The arrival of 'SIGCHLD' when a trap is set on 'SIGCHLD' does not
a0c0a00f
CR
6783 interrupt the 'wait' builtin and cause it to return immediately.
6784 The trap command is run once for each child that exits.
6785
d233b485 6786 58. The 'read' builtin may be interrupted by a signal for which a trap
a0c0a00f
CR
6787 has been set. If Bash receives a trapped signal while executing
6788 'read', the trap handler executes and 'read' returns an exit status
6789 greater than 128.
6790
d233b485 6791 59. Bash removes an exited background process's status from the list
a0c0a00f
CR
6792 of such statuses after the 'wait' builtin is used to obtain it.
6793
6794 There is other POSIX behavior that Bash does not implement by default
6795even when in POSIX mode. Specifically:
6796
6797 1. The 'fc' builtin checks '$EDITOR' as a program to edit history
6798 entries if 'FCEDIT' is unset, rather than defaulting directly to
6799 'ed'. 'fc' uses 'ed' if 'EDITOR' is unset.
6800
6801 2. As noted above, Bash requires the 'xpg_echo' option to be enabled
6802 for the 'echo' builtin to be fully conformant.
6803
6804 Bash can be configured to be POSIX-conformant by default, by
6805specifying the '--enable-strict-posix-default' to 'configure' when
6806building (*note Optional Features::).
6807
6808\1f
6809File: bash.info, Node: Job Control, Next: Command Line Editing, Prev: Bash Features, Up: Top
6810
68117 Job Control
6812*************
6813
6814This chapter discusses what job control is, how it works, and how Bash
6815allows you to access its facilities.
6816
6817* Menu:
6818
6819* Job Control Basics:: How job control works.
6820* Job Control Builtins:: Bash builtin commands used to interact
6821 with job control.
6822* Job Control Variables:: Variables Bash uses to customize job
6823 control.
6824
6825\1f
6826File: bash.info, Node: Job Control Basics, Next: Job Control Builtins, Up: Job Control
6827
68287.1 Job Control Basics
6829======================
6830
6831Job control refers to the ability to selectively stop (suspend) the
6832execution of processes and continue (resume) their execution at a later
6833point. A user typically employs this facility via an interactive
6834interface supplied jointly by the operating system kernel's terminal
6835driver and Bash.
6836
6837 The shell associates a JOB with each pipeline. It keeps a table of
6838currently executing jobs, which may be listed with the 'jobs' command.
6839When Bash starts a job asynchronously, it prints a line that looks like:
6840 [1] 25647
6841indicating that this job is job number 1 and that the process ID of the
6842last process in the pipeline associated with this job is 25647. All of
6843the processes in a single pipeline are members of the same job. Bash
6844uses the JOB abstraction as the basis for job control.
6845
6846 To facilitate the implementation of the user interface to job
6847control, the operating system maintains the notion of a current terminal
6848process group ID. Members of this process group (processes whose
6849process group ID is equal to the current terminal process group ID)
6850receive keyboard-generated signals such as 'SIGINT'. These processes
6851are said to be in the foreground. Background processes are those whose
6852process group ID differs from the terminal's; such processes are immune
6853to keyboard-generated signals. Only foreground processes are allowed to
6854read from or, if the user so specifies with 'stty tostop', write to the
6855terminal. Background processes which attempt to read from (write to
6856when 'stty tostop' is in effect) the terminal are sent a 'SIGTTIN'
6857('SIGTTOU') signal by the kernel's terminal driver, which, unless
6858caught, suspends the process.
6859
6860 If the operating system on which Bash is running supports job
6861control, Bash contains facilities to use it. Typing the SUSPEND
6862character (typically '^Z', Control-Z) while a process is running causes
6863that process to be stopped and returns control to Bash. Typing the
6864DELAYED SUSPEND character (typically '^Y', Control-Y) causes the process
6865to be stopped when it attempts to read input from the terminal, and
6866control to be returned to Bash. The user then manipulates the state of
6867this job, using the 'bg' command to continue it in the background, the
6868'fg' command to continue it in the foreground, or the 'kill' command to
6869kill it. A '^Z' takes effect immediately, and has the additional side
6870effect of causing pending output and typeahead to be discarded.
6871
6872 There are a number of ways to refer to a job in the shell. The
6873character '%' introduces a job specification (JOBSPEC).
6874
6875 Job number 'n' may be referred to as '%n'. The symbols '%%' and '%+'
6876refer to the shell's notion of the current job, which is the last job
6877stopped while it was in the foreground or started in the background. A
6878single '%' (with no accompanying job specification) also refers to the
6879current job. The previous job may be referenced using '%-'. If there
6880is only a single job, '%+' and '%-' can both be used to refer to that
6881job. In output pertaining to jobs (e.g., the output of the 'jobs'
6882command), the current job is always flagged with a '+', and the previous
6883job with a '-'.
6884
6885 A job may also be referred to using a prefix of the name used to
6886start it, or using a substring that appears in its command line. For
6887example, '%ce' refers to a stopped 'ce' job. Using '%?ce', on the other
6888hand, refers to any job containing the string 'ce' in its command line.
6889If the prefix or substring matches more than one job, Bash reports an
6890error.
6891
6892 Simply naming a job can be used to bring it into the foreground: '%1'
6893is a synonym for 'fg %1', bringing job 1 from the background into the
6894foreground. Similarly, '%1 &' resumes job 1 in the background,
6895equivalent to 'bg %1'
6896
6897 The shell learns immediately whenever a job changes state. Normally,
6898Bash waits until it is about to print a prompt before reporting changes
6899in a job's status so as to not interrupt any other output. If the '-b'
6900option to the 'set' builtin is enabled, Bash reports such changes
6901immediately (*note The Set Builtin::). Any trap on 'SIGCHLD' is
6902executed for each child process that exits.
6903
6904 If an attempt to exit Bash is made while jobs are stopped, (or
6905running, if the 'checkjobs' option is enabled - see *note The Shopt
6906Builtin::), the shell prints a warning message, and if the 'checkjobs'
6907option is enabled, lists the jobs and their statuses. The 'jobs'
6908command may then be used to inspect their status. If a second attempt
6909to exit is made without an intervening command, Bash does not print
6910another warning, and any stopped jobs are terminated.
6911
d233b485
CR
6912 When the shell is waiting for a job or process using the 'wait'
6913builtin, and job control is enabled, 'wait' will return when the job
6914changes state. The '-f' option will force 'wait' to wait until the job
6915or process terminates before returning.
6916
a0c0a00f
CR
6917\1f
6918File: bash.info, Node: Job Control Builtins, Next: Job Control Variables, Prev: Job Control Basics, Up: Job Control
6919
69207.2 Job Control Builtins
6921========================
6922
6923'bg'
6924 bg [JOBSPEC ...]
6925
6926 Resume each suspended job JOBSPEC in the background, as if it had
6927 been started with '&'. If JOBSPEC is not supplied, the current job
6928 is used. The return status is zero unless it is run when job
6929 control is not enabled, or, when run with job control enabled, any
6930 JOBSPEC was not found or specifies a job that was started without
6931 job control.
6932
6933'fg'
6934 fg [JOBSPEC]
6935
6936 Resume the job JOBSPEC in the foreground and make it the current
6937 job. If JOBSPEC is not supplied, the current job is used. The
6938 return status is that of the command placed into the foreground, or
6939 non-zero if run when job control is disabled or, when run with job
6940 control enabled, JOBSPEC does not specify a valid job or JOBSPEC
6941 specifies a job that was started without job control.
6942
6943'jobs'
6944 jobs [-lnprs] [JOBSPEC]
6945 jobs -x COMMAND [ARGUMENTS]
6946
6947 The first form lists the active jobs. The options have the
6948 following meanings:
6949
6950 '-l'
6951 List process IDs in addition to the normal information.
6952
6953 '-n'
6954 Display information only about jobs that have changed status
6955 since the user was last notified of their status.
6956
6957 '-p'
6958 List only the process ID of the job's process group leader.
6959
6960 '-r'
6961 Display only running jobs.
6962
6963 '-s'
6964 Display only stopped jobs.
6965
6966 If JOBSPEC is given, output is restricted to information about that
6967 job. If JOBSPEC is not supplied, the status of all jobs is listed.
6968
6969 If the '-x' option is supplied, 'jobs' replaces any JOBSPEC found
6970 in COMMAND or ARGUMENTS with the corresponding process group ID,
6971 and executes COMMAND, passing it ARGUMENTs, returning its exit
6972 status.
6973
6974'kill'
6975 kill [-s SIGSPEC] [-n SIGNUM] [-SIGSPEC] JOBSPEC or PID
6976 kill -l|-L [EXIT_STATUS]
6977
6978 Send a signal specified by SIGSPEC or SIGNUM to the process named
6979 by job specification JOBSPEC or process ID PID. SIGSPEC is either
6980 a case-insensitive signal name such as 'SIGINT' (with or without
6981 the 'SIG' prefix) or a signal number; SIGNUM is a signal number.
6982 If SIGSPEC and SIGNUM are not present, 'SIGTERM' is used. The '-l'
6983 option lists the signal names. If any arguments are supplied when
6984 '-l' is given, the names of the signals corresponding to the
6985 arguments are listed, and the return status is zero. EXIT_STATUS
6986 is a number specifying a signal number or the exit status of a
6987 process terminated by a signal. The '-L' option is equivalent to
6988 '-l'. The return status is zero if at least one signal was
6989 successfully sent, or non-zero if an error occurs or an invalid
6990 option is encountered.
6991
6992'wait'
d233b485 6993 wait [-fn] [JOBSPEC or PID ...]
a0c0a00f
CR
6994
6995 Wait until the child process specified by each process ID PID or
6996 job specification JOBSPEC exits and return the exit status of the
6997 last command waited for. If a job spec is given, all processes in
6998 the job are waited for. If no arguments are given, all currently
6999 active child processes are waited for, and the return status is
7000 zero. If the '-n' option is supplied, 'wait' waits for any job to
d233b485
CR
7001 terminate and returns its exit status. If the '-f' option is
7002 supplied, and job control is enabled, 'wait' forces each PID or
7003 JOBSPEC to terminate before returning its status, intead of
7004 returning when it changes status. If neither JOBSPEC nor PID
a0c0a00f
CR
7005 specifies an active child process of the shell, the return status
7006 is 127.
7007
7008'disown'
7009 disown [-ar] [-h] [JOBSPEC ... | PID ... ]
7010
7011 Without options, remove each JOBSPEC from the table of active jobs.
7012 If the '-h' option is given, the job is not removed from the table,
7013 but is marked so that 'SIGHUP' is not sent to the job if the shell
7014 receives a 'SIGHUP'. If JOBSPEC is not present, and neither the
7015 '-a' nor the '-r' option is supplied, the current job is used. If
7016 no JOBSPEC is supplied, the '-a' option means to remove or mark all
7017 jobs; the '-r' option without a JOBSPEC argument restricts
7018 operation to running jobs.
7019
7020'suspend'
7021 suspend [-f]
7022
7023 Suspend the execution of this shell until it receives a 'SIGCONT'
7024 signal. A login shell cannot be suspended; the '-f' option can be
7025 used to override this and force the suspension.
7026
7027 When job control is not active, the 'kill' and 'wait' builtins do not
7028accept JOBSPEC arguments. They must be supplied process IDs.
7029
7030\1f
7031File: bash.info, Node: Job Control Variables, Prev: Job Control Builtins, Up: Job Control
7032
70337.3 Job Control Variables
7034=========================
7035
7036'auto_resume'
7037 This variable controls how the shell interacts with the user and
7038 job control. If this variable exists then single word simple
7039 commands without redirections are treated as candidates for
7040 resumption of an existing job. There is no ambiguity allowed; if
7041 there is more than one job beginning with the string typed, then
7042 the most recently accessed job will be selected. The name of a
7043 stopped job, in this context, is the command line used to start it.
7044 If this variable is set to the value 'exact', the string supplied
7045 must match the name of a stopped job exactly; if set to
7046 'substring', the string supplied needs to match a substring of the
7047 name of a stopped job. The 'substring' value provides
7048 functionality analogous to the '%?' job ID (*note Job Control
7049 Basics::). If set to any other value, the supplied string must be
7050 a prefix of a stopped job's name; this provides functionality
7051 analogous to the '%' job ID.
7052
7053\1f
7054File: bash.info, Node: Command Line Editing, Next: Using History Interactively, Prev: Job Control, Up: Top
7055
70568 Command Line Editing
7057**********************
7058
7059This chapter describes the basic features of the GNU command line
7060editing interface. Command line editing is provided by the Readline
7061library, which is used by several different programs, including Bash.
7062Command line editing is enabled by default when using an interactive
7063shell, unless the '--noediting' option is supplied at shell invocation.
7064Line editing is also used when using the '-e' option to the 'read'
7065builtin command (*note Bash Builtins::). By default, the line editing
7066commands are similar to those of Emacs. A vi-style line editing
7067interface is also available. Line editing can be enabled at any time
7068using the '-o emacs' or '-o vi' options to the 'set' builtin command
7069(*note The Set Builtin::), or disabled using the '+o emacs' or '+o vi'
7070options to 'set'.
7071
7072* Menu:
7073
7074* Introduction and Notation:: Notation used in this text.
7075* Readline Interaction:: The minimum set of commands for editing a line.
7076* Readline Init File:: Customizing Readline from a user's view.
7077* Bindable Readline Commands:: A description of most of the Readline commands
7078 available for binding
7079* Readline vi Mode:: A short description of how to make Readline
7080 behave like the vi editor.
7081* Programmable Completion:: How to specify the possible completions for
7082 a specific command.
7083* Programmable Completion Builtins:: Builtin commands to specify how to
7084 complete arguments for a particular command.
7085* A Programmable Completion Example:: An example shell function for
7086 generating possible completions.
7087
7088\1f
7089File: bash.info, Node: Introduction and Notation, Next: Readline Interaction, Up: Command Line Editing
7090
70918.1 Introduction to Line Editing
7092================================
7093
7094The following paragraphs describe the notation used to represent
7095keystrokes.
7096
7097 The text 'C-k' is read as 'Control-K' and describes the character
7098produced when the <k> key is pressed while the Control key is depressed.
7099
7100 The text 'M-k' is read as 'Meta-K' and describes the character
7101produced when the Meta key (if you have one) is depressed, and the <k>
7102key is pressed. The Meta key is labeled <ALT> on many keyboards. On
7103keyboards with two keys labeled <ALT> (usually to either side of the
7104space bar), the <ALT> on the left side is generally set to work as a
7105Meta key. The <ALT> key on the right may also be configured to work as
7106a Meta key or may be configured as some other modifier, such as a
7107Compose key for typing accented characters.
7108
7109 If you do not have a Meta or <ALT> key, or another key working as a
7110Meta key, the identical keystroke can be generated by typing <ESC>
7111_first_, and then typing <k>. Either process is known as "metafying"
7112the <k> key.
7113
7114 The text 'M-C-k' is read as 'Meta-Control-k' and describes the
7115character produced by "metafying" 'C-k'.
7116
7117 In addition, several keys have their own names. Specifically, <DEL>,
7118<ESC>, <LFD>, <SPC>, <RET>, and <TAB> all stand for themselves when seen
7119in this text, or in an init file (*note Readline Init File::). If your
7120keyboard lacks a <LFD> key, typing <C-j> will produce the desired
7121character. The <RET> key may be labeled <Return> or <Enter> on some
7122keyboards.
7123
7124\1f
7125File: bash.info, Node: Readline Interaction, Next: Readline Init File, Prev: Introduction and Notation, Up: Command Line Editing
7126
71278.2 Readline Interaction
7128========================
7129
7130Often during an interactive session you type in a long line of text,
7131only to notice that the first word on the line is misspelled. The
7132Readline library gives you a set of commands for manipulating the text
7133as you type it in, allowing you to just fix your typo, and not forcing
7134you to retype the majority of the line. Using these editing commands,
7135you move the cursor to the place that needs correction, and delete or
7136insert the text of the corrections. Then, when you are satisfied with
7137the line, you simply press <RET>. You do not have to be at the end of
7138the line to press <RET>; the entire line is accepted regardless of the
7139location of the cursor within the line.
7140
7141* Menu:
7142
7143* Readline Bare Essentials:: The least you need to know about Readline.
7144* Readline Movement Commands:: Moving about the input line.
7145* Readline Killing Commands:: How to delete text, and how to get it back!
7146* Readline Arguments:: Giving numeric arguments to commands.
7147* Searching:: Searching through previous lines.
7148
7149\1f
7150File: bash.info, Node: Readline Bare Essentials, Next: Readline Movement Commands, Up: Readline Interaction
7151
71528.2.1 Readline Bare Essentials
7153------------------------------
7154
7155In order to enter characters into the line, simply type them. The typed
7156character appears where the cursor was, and then the cursor moves one
7157space to the right. If you mistype a character, you can use your erase
7158character to back up and delete the mistyped character.
7159
7160 Sometimes you may mistype a character, and not notice the error until
7161you have typed several other characters. In that case, you can type
7162'C-b' to move the cursor to the left, and then correct your mistake.
7163Afterwards, you can move the cursor to the right with 'C-f'.
7164
7165 When you add text in the middle of a line, you will notice that
7166characters to the right of the cursor are 'pushed over' to make room for
7167the text that you have inserted. Likewise, when you delete text behind
7168the cursor, characters to the right of the cursor are 'pulled back' to
7169fill in the blank space created by the removal of the text. A list of
7170the bare essentials for editing the text of an input line follows.
7171
7172'C-b'
7173 Move back one character.
7174'C-f'
7175 Move forward one character.
7176<DEL> or <Backspace>
7177 Delete the character to the left of the cursor.
7178'C-d'
7179 Delete the character underneath the cursor.
7180Printing characters
7181 Insert the character into the line at the cursor.
7182'C-_' or 'C-x C-u'
7183 Undo the last editing command. You can undo all the way back to an
7184 empty line.
7185
7186(Depending on your configuration, the <Backspace> key be set to delete
7187the character to the left of the cursor and the <DEL> key set to delete
7188the character underneath the cursor, like 'C-d', rather than the
7189character to the left of the cursor.)
7190
7191\1f
7192File: bash.info, Node: Readline Movement Commands, Next: Readline Killing Commands, Prev: Readline Bare Essentials, Up: Readline Interaction
7193
71948.2.2 Readline Movement Commands
7195--------------------------------
7196
7197The above table describes the most basic keystrokes that you need in
7198order to do editing of the input line. For your convenience, many other
7199commands have been added in addition to 'C-b', 'C-f', 'C-d', and <DEL>.
7200Here are some commands for moving more rapidly about the line.
7201
7202'C-a'
7203 Move to the start of the line.
7204'C-e'
7205 Move to the end of the line.
7206'M-f'
7207 Move forward a word, where a word is composed of letters and
7208 digits.
7209'M-b'
7210 Move backward a word.
7211'C-l'
7212 Clear the screen, reprinting the current line at the top.
7213
7214 Notice how 'C-f' moves forward a character, while 'M-f' moves forward
7215a word. It is a loose convention that control keystrokes operate on
7216characters while meta keystrokes operate on words.
7217
7218\1f
7219File: bash.info, Node: Readline Killing Commands, Next: Readline Arguments, Prev: Readline Movement Commands, Up: Readline Interaction
7220
72218.2.3 Readline Killing Commands
7222-------------------------------
7223
7224"Killing" text means to delete the text from the line, but to save it
7225away for later use, usually by "yanking" (re-inserting) it back into the
7226line. ('Cut' and 'paste' are more recent jargon for 'kill' and 'yank'.)
7227
7228 If the description for a command says that it 'kills' text, then you
7229can be sure that you can get the text back in a different (or the same)
7230place later.
7231
7232 When you use a kill command, the text is saved in a "kill-ring". Any
7233number of consecutive kills save all of the killed text together, so
7234that when you yank it back, you get it all. The kill ring is not line
7235specific; the text that you killed on a previously typed line is
7236available to be yanked back later, when you are typing another line.
7237
7238 Here is the list of commands for killing text.
7239
7240'C-k'
7241 Kill the text from the current cursor position to the end of the
7242 line.
7243
7244'M-d'
7245 Kill from the cursor to the end of the current word, or, if between
7246 words, to the end of the next word. Word boundaries are the same
7247 as those used by 'M-f'.
7248
7249'M-<DEL>'
7250 Kill from the cursor the start of the current word, or, if between
7251 words, to the start of the previous word. Word boundaries are the
7252 same as those used by 'M-b'.
7253
7254'C-w'
7255 Kill from the cursor to the previous whitespace. This is different
7256 than 'M-<DEL>' because the word boundaries differ.
7257
7258 Here is how to "yank" the text back into the line. Yanking means to
7259copy the most-recently-killed text from the kill buffer.
7260
7261'C-y'
7262 Yank the most recently killed text back into the buffer at the
7263 cursor.
7264
7265'M-y'
7266 Rotate the kill-ring, and yank the new top. You can only do this
7267 if the prior command is 'C-y' or 'M-y'.
7268
7269\1f
7270File: bash.info, Node: Readline Arguments, Next: Searching, Prev: Readline Killing Commands, Up: Readline Interaction
7271
72728.2.4 Readline Arguments
7273------------------------
7274
7275You can pass numeric arguments to Readline commands. Sometimes the
7276argument acts as a repeat count, other times it is the sign of the
7277argument that is significant. If you pass a negative argument to a
7278command which normally acts in a forward direction, that command will
7279act in a backward direction. For example, to kill text back to the
7280start of the line, you might type 'M-- C-k'.
7281
7282 The general way to pass numeric arguments to a command is to type
7283meta digits before the command. If the first 'digit' typed is a minus
7284sign ('-'), then the sign of the argument will be negative. Once you
7285have typed one meta digit to get the argument started, you can type the
7286remainder of the digits, and then the command. For example, to give the
7287'C-d' command an argument of 10, you could type 'M-1 0 C-d', which will
7288delete the next ten characters on the input line.
7289
7290\1f
7291File: bash.info, Node: Searching, Prev: Readline Arguments, Up: Readline Interaction
7292
72938.2.5 Searching for Commands in the History
7294-------------------------------------------
7295
7296Readline provides commands for searching through the command history
7297(*note Bash History Facilities::) for lines containing a specified
7298string. There are two search modes: "incremental" and
7299"non-incremental".
7300
7301 Incremental searches begin before the user has finished typing the
7302search string. As each character of the search string is typed,
7303Readline displays the next entry from the history matching the string
7304typed so far. An incremental search requires only as many characters as
7305needed to find the desired history entry. To search backward in the
7306history for a particular string, type 'C-r'. Typing 'C-s' searches
7307forward through the history. The characters present in the value of the
7308'isearch-terminators' variable are used to terminate an incremental
7309search. If that variable has not been assigned a value, the <ESC> and
7310'C-J' characters will terminate an incremental search. 'C-g' will abort
7311an incremental search and restore the original line. When the search is
7312terminated, the history entry containing the search string becomes the
7313current line.
7314
7315 To find other matching entries in the history list, type 'C-r' or
7316'C-s' as appropriate. This will search backward or forward in the
7317history for the next entry matching the search string typed so far. Any
7318other key sequence bound to a Readline command will terminate the search
7319and execute that command. For instance, a <RET> will terminate the
7320search and accept the line, thereby executing the command from the
7321history list. A movement command will terminate the search, make the
7322last line found the current line, and begin editing.
7323
7324 Readline remembers the last incremental search string. If two 'C-r's
7325are typed without any intervening characters defining a new search
7326string, any remembered search string is used.
7327
7328 Non-incremental searches read the entire search string before
7329starting to search for matching history lines. The search string may be
7330typed by the user or be part of the contents of the current line.
7331
7332\1f
7333File: bash.info, Node: Readline Init File, Next: Bindable Readline Commands, Prev: Readline Interaction, Up: Command Line Editing
7334
73358.3 Readline Init File
7336======================
7337
7338Although the Readline library comes with a set of Emacs-like keybindings
7339installed by default, it is possible to use a different set of
7340keybindings. Any user can customize programs that use Readline by
7341putting commands in an "inputrc" file, conventionally in his home
7342directory. The name of this file is taken from the value of the shell
7343variable 'INPUTRC'. If that variable is unset, the default is
7344'~/.inputrc'. If that file does not exist or cannot be read, the
7345ultimate default is '/etc/inputrc'.
7346
7347 When a program which uses the Readline library starts up, the init
7348file is read, and the key bindings are set.
7349
7350 In addition, the 'C-x C-r' command re-reads this init file, thus
7351incorporating any changes that you might have made to it.
7352
7353* Menu:
7354
7355* Readline Init File Syntax:: Syntax for the commands in the inputrc file.
7356
7357* Conditional Init Constructs:: Conditional key bindings in the inputrc file.
7358
7359* Sample Init File:: An example inputrc file.
7360
7361\1f
7362File: bash.info, Node: Readline Init File Syntax, Next: Conditional Init Constructs, Up: Readline Init File
7363
73648.3.1 Readline Init File Syntax
7365-------------------------------
7366
7367There are only a few basic constructs allowed in the Readline init file.
7368Blank lines are ignored. Lines beginning with a '#' are comments.
7369Lines beginning with a '$' indicate conditional constructs (*note
7370Conditional Init Constructs::). Other lines denote variable settings
7371and key bindings.
7372
7373Variable Settings
7374 You can modify the run-time behavior of Readline by altering the
7375 values of variables in Readline using the 'set' command within the
7376 init file. The syntax is simple:
7377
7378 set VARIABLE VALUE
7379
7380 Here, for example, is how to change from the default Emacs-like key
7381 binding to use 'vi' line editing commands:
7382
7383 set editing-mode vi
7384
7385 Variable names and values, where appropriate, are recognized
7386 without regard to case. Unrecognized variable names are ignored.
7387
7388 Boolean variables (those that can be set to on or off) are set to
7389 on if the value is null or empty, ON (case-insensitive), or 1. Any
7390 other value results in the variable being set to off.
7391
7392 The 'bind -V' command lists the current Readline variable names and
7393 values. *Note Bash Builtins::.
7394
7395 A great deal of run-time behavior is changeable with the following
7396 variables.
7397
7398 'bell-style'
7399 Controls what happens when Readline wants to ring the terminal
7400 bell. If set to 'none', Readline never rings the bell. If
7401 set to 'visible', Readline uses a visible bell if one is
7402 available. If set to 'audible' (the default), Readline
7403 attempts to ring the terminal's bell.
7404
7405 'bind-tty-special-chars'
7406 If set to 'on' (the default), Readline attempts to bind the
7407 control characters treated specially by the kernel's terminal
7408 driver to their Readline equivalents.
7409
7410 'blink-matching-paren'
7411 If set to 'on', Readline attempts to briefly move the cursor
7412 to an opening parenthesis when a closing parenthesis is
7413 inserted. The default is 'off'.
7414
7415 'colored-completion-prefix'
7416 If set to 'on', when listing completions, Readline displays
7417 the common prefix of the set of possible completions using a
7418 different color. The color definitions are taken from the
7419 value of the 'LS_COLORS' environment variable. The default is
7420 'off'.
7421
7422 'colored-stats'
7423 If set to 'on', Readline displays possible completions using
7424 different colors to indicate their file type. The color
7425 definitions are taken from the value of the 'LS_COLORS'
7426 environment variable. The default is 'off'.
7427
7428 'comment-begin'
7429 The string to insert at the beginning of the line when the
7430 'insert-comment' command is executed. The default value is
7431 '"#"'.
7432
7433 'completion-display-width'
7434 The number of screen columns used to display possible matches
7435 when performing completion. The value is ignored if it is
7436 less than 0 or greater than the terminal screen width. A
7437 value of 0 will cause matches to be displayed one per line.
7438 The default value is -1.
7439
7440 'completion-ignore-case'
7441 If set to 'on', Readline performs filename matching and
7442 completion in a case-insensitive fashion. The default value
7443 is 'off'.
7444
7445 'completion-map-case'
7446 If set to 'on', and COMPLETION-IGNORE-CASE is enabled,
7447 Readline treats hyphens ('-') and underscores ('_') as
7448 equivalent when performing case-insensitive filename matching
d233b485 7449 and completion. The default value is 'off'.
a0c0a00f
CR
7450
7451 'completion-prefix-display-length'
7452 The length in characters of the common prefix of a list of
7453 possible completions that is displayed without modification.
7454 When set to a value greater than zero, common prefixes longer
7455 than this value are replaced with an ellipsis when displaying
7456 possible completions.
7457
7458 'completion-query-items'
7459 The number of possible completions that determines when the
7460 user is asked whether the list of possibilities should be
7461 displayed. If the number of possible completions is greater
7462 than this value, Readline will ask the user whether or not he
7463 wishes to view them; otherwise, they are simply listed. This
7464 variable must be set to an integer value greater than or equal
7465 to 0. A negative value means Readline should never ask. The
7466 default limit is '100'.
7467
7468 'convert-meta'
7469 If set to 'on', Readline will convert characters with the
7470 eighth bit set to an ASCII key sequence by stripping the
7471 eighth bit and prefixing an <ESC> character, converting them
7472 to a meta-prefixed key sequence. The default value is 'on',
7473 but will be set to 'off' if the locale is one that contains
7474 eight-bit characters.
7475
7476 'disable-completion'
7477 If set to 'On', Readline will inhibit word completion.
7478 Completion characters will be inserted into the line as if
7479 they had been mapped to 'self-insert'. The default is 'off'.
7480
7481 'echo-control-characters'
7482 When set to 'on', on operating systems that indicate they
7483 support it, readline echoes a character corresponding to a
7484 signal generated from the keyboard. The default is 'on'.
7485
7486 'editing-mode'
7487 The 'editing-mode' variable controls which default set of key
7488 bindings is used. By default, Readline starts up in Emacs
7489 editing mode, where the keystrokes are most similar to Emacs.
7490 This variable can be set to either 'emacs' or 'vi'.
7491
7492 'emacs-mode-string'
d233b485
CR
7493 If the SHOW-MODE-IN-PROMPT variable is enabled, this string is
7494 displayed immediately before the last line of the primary
7495 prompt when emacs editing mode is active. The value is
7496 expanded like a key binding, so the standard set of meta- and
7497 control prefixes and backslash escape sequences is available.
7498 Use the '\1' and '\2' escapes to begin and end sequences of
7499 non-printing characters, which can be used to embed a terminal
7500 control sequence into the mode string. The default is '@'.
a0c0a00f
CR
7501
7502 'enable-bracketed-paste'
7503 When set to 'On', Readline will configure the terminal in a
7504 way that will enable it to insert each paste into the editing
7505 buffer as a single string of characters, instead of treating
7506 each character as if it had been read from the keyboard. This
7507 can prevent pasted characters from being interpreted as
7508 editing commands. The default is 'off'.
7509
7510 'enable-keypad'
7511 When set to 'on', Readline will try to enable the application
7512 keypad when it is called. Some systems need this to enable
7513 the arrow keys. The default is 'off'.
7514
7515 'enable-meta-key'
7516 When set to 'on', Readline will try to enable any meta
7517 modifier key the terminal claims to support when it is called.
7518 On many terminals, the meta key is used to send eight-bit
7519 characters. The default is 'on'.
7520
7521 'expand-tilde'
7522 If set to 'on', tilde expansion is performed when Readline
7523 attempts word completion. The default is 'off'.
7524
7525 'history-preserve-point'
7526 If set to 'on', the history code attempts to place the point
7527 (the current cursor position) at the same location on each
7528 history line retrieved with 'previous-history' or
7529 'next-history'. The default is 'off'.
7530
7531 'history-size'
7532 Set the maximum number of history entries saved in the history
7533 list. If set to zero, any existing history entries are
7534 deleted and no new entries are saved. If set to a value less
7535 than zero, the number of history entries is not limited. By
7536 default, the number of history entries is not limited. If an
7537 attempt is made to set HISTORY-SIZE to a non-numeric value,
7538 the maximum number of history entries will be set to 500.
7539
7540 'horizontal-scroll-mode'
7541 This variable can be set to either 'on' or 'off'. Setting it
7542 to 'on' means that the text of the lines being edited will
7543 scroll horizontally on a single screen line when they are
7544 longer than the width of the screen, instead of wrapping onto
7545 a new screen line. By default, this variable is set to 'off'.
7546
7547 'input-meta'
7548 If set to 'on', Readline will enable eight-bit input (it will
7549 not clear the eighth bit in the characters it reads),
7550 regardless of what the terminal claims it can support. The
7551 default value is 'off', but Readline will set it to 'on' if
7552 the locale contains eight-bit characters. The name
7553 'meta-flag' is a synonym for this variable.
7554
7555 'isearch-terminators'
7556 The string of characters that should terminate an incremental
7557 search without subsequently executing the character as a
7558 command (*note Searching::). If this variable has not been
7559 given a value, the characters <ESC> and 'C-J' will terminate
7560 an incremental search.
7561
7562 'keymap'
7563 Sets Readline's idea of the current keymap for key binding
d233b485 7564 commands. Built-in 'keymap' names are 'emacs',
a0c0a00f
CR
7565 'emacs-standard', 'emacs-meta', 'emacs-ctlx', 'vi', 'vi-move',
7566 'vi-command', and 'vi-insert'. 'vi' is equivalent to
7567 'vi-command' ('vi-move' is also a synonym); 'emacs' is
d233b485
CR
7568 equivalent to 'emacs-standard'. Applications may add
7569 additional names. The default value is 'emacs'. The value of
7570 the 'editing-mode' variable also affects the default keymap.
a0c0a00f
CR
7571
7572 'keyseq-timeout'
7573 Specifies the duration Readline will wait for a character when
7574 reading an ambiguous key sequence (one that can form a
7575 complete key sequence using the input read so far, or can take
7576 additional input to complete a longer key sequence). If no
7577 input is received within the timeout, Readline will use the
7578 shorter but complete key sequence. Readline uses this value
7579 to determine whether or not input is available on the current
7580 input source ('rl_instream' by default). The value is
7581 specified in milliseconds, so a value of 1000 means that
7582 Readline will wait one second for additional input. If this
7583 variable is set to a value less than or equal to zero, or to a
7584 non-numeric value, Readline will wait until another key is
7585 pressed to decide which key sequence to complete. The default
7586 value is '500'.
7587
7588 'mark-directories'
7589 If set to 'on', completed directory names have a slash
7590 appended. The default is 'on'.
7591
7592 'mark-modified-lines'
7593 This variable, when set to 'on', causes Readline to display an
7594 asterisk ('*') at the start of history lines which have been
7595 modified. This variable is 'off' by default.
7596
7597 'mark-symlinked-directories'
7598 If set to 'on', completed names which are symbolic links to
7599 directories have a slash appended (subject to the value of
7600 'mark-directories'). The default is 'off'.
7601
7602 'match-hidden-files'
7603 This variable, when set to 'on', causes Readline to match
7604 files whose names begin with a '.' (hidden files) when
7605 performing filename completion. If set to 'off', the leading
7606 '.' must be supplied by the user in the filename to be
7607 completed. This variable is 'on' by default.
7608
7609 'menu-complete-display-prefix'
7610 If set to 'on', menu completion displays the common prefix of
7611 the list of possible completions (which may be empty) before
7612 cycling through the list. The default is 'off'.
7613
7614 'output-meta'
7615 If set to 'on', Readline will display characters with the
7616 eighth bit set directly rather than as a meta-prefixed escape
7617 sequence. The default is 'off', but Readline will set it to
7618 'on' if the locale contains eight-bit characters.
7619
7620 'page-completions'
7621 If set to 'on', Readline uses an internal 'more'-like pager to
7622 display a screenful of possible completions at a time. This
7623 variable is 'on' by default.
7624
7625 'print-completions-horizontally'
7626 If set to 'on', Readline will display completions with matches
7627 sorted horizontally in alphabetical order, rather than down
7628 the screen. The default is 'off'.
7629
7630 'revert-all-at-newline'
7631 If set to 'on', Readline will undo all changes to history
7632 lines before returning when 'accept-line' is executed. By
7633 default, history lines may be modified and retain individual
7634 undo lists across calls to 'readline'. The default is 'off'.
7635
7636 'show-all-if-ambiguous'
7637 This alters the default behavior of the completion functions.
7638 If set to 'on', words which have more than one possible
7639 completion cause the matches to be listed immediately instead
7640 of ringing the bell. The default value is 'off'.
7641
7642 'show-all-if-unmodified'
7643 This alters the default behavior of the completion functions
7644 in a fashion similar to SHOW-ALL-IF-AMBIGUOUS. If set to
7645 'on', words which have more than one possible completion
7646 without any possible partial completion (the possible
7647 completions don't share a common prefix) cause the matches to
7648 be listed immediately instead of ringing the bell. The
7649 default value is 'off'.
7650
7651 'show-mode-in-prompt'
d233b485 7652 If set to 'on', add a string to the beginning of the prompt
a0c0a00f 7653 indicating the editing mode: emacs, vi command, or vi
d233b485
CR
7654 insertion. The mode strings are user-settable (e.g.,
7655 EMACS-MODE-STRING). The default value is 'off'.
a0c0a00f
CR
7656
7657 'skip-completed-text'
7658 If set to 'on', this alters the default completion behavior
7659 when inserting a single match into the line. It's only active
7660 when performing completion in the middle of a word. If
7661 enabled, readline does not insert characters from the
7662 completion that match characters after point in the word being
7663 completed, so portions of the word following the cursor are
7664 not duplicated. For instance, if this is enabled, attempting
7665 completion when the cursor is after the 'e' in 'Makefile' will
7666 result in 'Makefile' rather than 'Makefilefile', assuming
7667 there is a single possible completion. The default value is
7668 'off'.
7669
7670 'vi-cmd-mode-string'
d233b485
CR
7671 If the SHOW-MODE-IN-PROMPT variable is enabled, this string is
7672 displayed immediately before the last line of the primary
7673 prompt when vi editing mode is active and in command mode.
7674 The value is expanded like a key binding, so the standard set
7675 of meta- and control prefixes and backslash escape sequences
7676 is available. Use the '\1' and '\2' escapes to begin and end
7677 sequences of non-printing characters, which can be used to
7678 embed a terminal control sequence into the mode string. The
7679 default is '(cmd)'.
a0c0a00f
CR
7680
7681 'vi-ins-mode-string'
d233b485
CR
7682 If the SHOW-MODE-IN-PROMPT variable is enabled, this string is
7683 displayed immediately before the last line of the primary
7684 prompt when vi editing mode is active and in insertion mode.
7685 The value is expanded like a key binding, so the standard set
7686 of meta- and control prefixes and backslash escape sequences
7687 is available. Use the '\1' and '\2' escapes to begin and end
7688 sequences of non-printing characters, which can be used to
7689 embed a terminal control sequence into the mode string. The
7690 default is '(ins)'.
a0c0a00f
CR
7691
7692 'visible-stats'
7693 If set to 'on', a character denoting a file's type is appended
7694 to the filename when listing possible completions. The
7695 default is 'off'.
7696
7697Key Bindings
7698 The syntax for controlling key bindings in the init file is simple.
7699 First you need to find the name of the command that you want to
7700 change. The following sections contain tables of the command name,
7701 the default keybinding, if any, and a short description of what the
7702 command does.
7703
7704 Once you know the name of the command, simply place on a line in
7705 the init file the name of the key you wish to bind the command to,
7706 a colon, and then the name of the command. There can be no space
7707 between the key name and the colon - that will be interpreted as
7708 part of the key name. The name of the key can be expressed in
7709 different ways, depending on what you find most comfortable.
7710
7711 In addition to command names, readline allows keys to be bound to a
7712 string that is inserted when the key is pressed (a MACRO).
7713
7714 The 'bind -p' command displays Readline function names and bindings
7715 in a format that can put directly into an initialization file.
7716 *Note Bash Builtins::.
7717
7718 KEYNAME: FUNCTION-NAME or MACRO
7719 KEYNAME is the name of a key spelled out in English. For
7720 example:
7721 Control-u: universal-argument
7722 Meta-Rubout: backward-kill-word
7723 Control-o: "> output"
7724
d233b485 7725 In the example above, 'C-u' is bound to the function
a0c0a00f
CR
7726 'universal-argument', 'M-DEL' is bound to the function
7727 'backward-kill-word', and 'C-o' is bound to run the macro
7728 expressed on the right hand side (that is, to insert the text
7729 '> output' into the line).
7730
7731 A number of symbolic character names are recognized while
7732 processing this key binding syntax: DEL, ESC, ESCAPE, LFD,
7733 NEWLINE, RET, RETURN, RUBOUT, SPACE, SPC, and TAB.
7734
7735 "KEYSEQ": FUNCTION-NAME or MACRO
7736 KEYSEQ differs from KEYNAME above in that strings denoting an
7737 entire key sequence can be specified, by placing the key
7738 sequence in double quotes. Some GNU Emacs style key escapes
7739 can be used, as in the following example, but the special
7740 character names are not recognized.
7741
7742 "\C-u": universal-argument
7743 "\C-x\C-r": re-read-init-file
7744 "\e[11~": "Function Key 1"
7745
7746 In the above example, 'C-u' is again bound to the function
7747 'universal-argument' (just as it was in the first example),
7748 ''C-x' 'C-r'' is bound to the function 're-read-init-file',
7749 and '<ESC> <[> <1> <1> <~>' is bound to insert the text
7750 'Function Key 1'.
7751
7752 The following GNU Emacs style escape sequences are available when
7753 specifying key sequences:
7754
7755 '\C-'
7756 control prefix
7757 '\M-'
7758 meta prefix
7759 '\e'
7760 an escape character
7761 '\\'
7762 backslash
7763 '\"'
7764 <">, a double quotation mark
7765 '\''
7766 <'>, a single quote or apostrophe
7767
7768 In addition to the GNU Emacs style escape sequences, a second set
7769 of backslash escapes is available:
7770
7771 '\a'
7772 alert (bell)
7773 '\b'
7774 backspace
7775 '\d'
7776 delete
7777 '\f'
7778 form feed
7779 '\n'
7780 newline
7781 '\r'
7782 carriage return
7783 '\t'
7784 horizontal tab
7785 '\v'
7786 vertical tab
7787 '\NNN'
7788 the eight-bit character whose value is the octal value NNN
7789 (one to three digits)
7790 '\xHH'
7791 the eight-bit character whose value is the hexadecimal value
7792 HH (one or two hex digits)
7793
7794 When entering the text of a macro, single or double quotes must be
7795 used to indicate a macro definition. Unquoted text is assumed to
7796 be a function name. In the macro body, the backslash escapes
7797 described above are expanded. Backslash will quote any other
7798 character in the macro text, including '"' and '''. For example,
7799 the following binding will make ''C-x' \' insert a single '\' into
7800 the line:
7801 "\C-x\\": "\\"
7802
7803\1f
7804File: bash.info, Node: Conditional Init Constructs, Next: Sample Init File, Prev: Readline Init File Syntax, Up: Readline Init File
7805
78068.3.2 Conditional Init Constructs
7807---------------------------------
7808
7809Readline implements a facility similar in spirit to the conditional
7810compilation features of the C preprocessor which allows key bindings and
7811variable settings to be performed as the result of tests. There are
7812four parser directives used.
7813
7814'$if'
7815 The '$if' construct allows bindings to be made based on the editing
7816 mode, the terminal being used, or the application using Readline.
d233b485
CR
7817 The text of the test, after any comparison operator, extends to the
7818 end of the line; unless otherwise noted, no characters are required
7819 to isolate it.
a0c0a00f
CR
7820
7821 'mode'
7822 The 'mode=' form of the '$if' directive is used to test
7823 whether Readline is in 'emacs' or 'vi' mode. This may be used
7824 in conjunction with the 'set keymap' command, for instance, to
7825 set bindings in the 'emacs-standard' and 'emacs-ctlx' keymaps
7826 only if Readline is starting out in 'emacs' mode.
7827
7828 'term'
7829 The 'term=' form may be used to include terminal-specific key
7830 bindings, perhaps to bind the key sequences output by the
7831 terminal's function keys. The word on the right side of the
7832 '=' is tested against both the full name of the terminal and
7833 the portion of the terminal name before the first '-'. This
7834 allows 'sun' to match both 'sun' and 'sun-cmd', for instance.
7835
d233b485
CR
7836 'version'
7837 The 'version' test may be used to perform comparisons against
7838 specific Readline versions. The 'version' expands to the
7839 current Readline version. The set of comparison operators
7840 includes '=' (and '=='), '!=', '<=', '>=', '<', and '>'. The
7841 version number supplied on the right side of the operator
7842 consists of a major version number, an optional decimal point,
7843 and an optional minor version (e.g., '7.1'). If the minor
7844 version is omitted, it is assumed to be '0'. The operator may
7845 be separated from the string 'version' and from the version
7846 number argument by whitespace. The following example sets a
7847 variable if the Readline version being used is 7.0 or newer:
7848 $if version >= 7.0
7849 set show-mode-in-prompt on
7850 $endif
7851
a0c0a00f
CR
7852 'application'
7853 The APPLICATION construct is used to include
7854 application-specific settings. Each program using the
7855 Readline library sets the APPLICATION NAME, and you can test
7856 for a particular value. This could be used to bind key
7857 sequences to functions useful for a specific program. For
7858 instance, the following command adds a key sequence that
7859 quotes the current or previous word in Bash:
7860 $if Bash
7861 # Quote the current or previous word
7862 "\C-xq": "\eb\"\ef\""
7863 $endif
7864
d233b485
CR
7865 'variable'
7866 The VARIABLE construct provides simple equality tests for
7867 Readline variables and values. The permitted comparison
7868 operators are '=', '==', and '!='. The variable name must be
7869 separated from the comparison operator by whitespace; the
7870 operator may be separated from the value on the right hand
7871 side by whitespace. Both string and boolean variables may be
7872 tested. Boolean variables must be tested against the values
7873 ON and OFF. The following example is equivalent to the
7874 'mode=emacs' test described above:
7875 $if editing-mode == emacs
7876 set show-mode-in-prompt on
7877 $endif
7878
a0c0a00f
CR
7879'$endif'
7880 This command, as seen in the previous example, terminates an '$if'
7881 command.
7882
7883'$else'
7884 Commands in this branch of the '$if' directive are executed if the
7885 test fails.
7886
7887'$include'
7888 This directive takes a single filename as an argument and reads
7889 commands and bindings from that file. For example, the following
7890 directive reads from '/etc/inputrc':
7891 $include /etc/inputrc
7892
7893\1f
7894File: bash.info, Node: Sample Init File, Prev: Conditional Init Constructs, Up: Readline Init File
7895
78968.3.3 Sample Init File
7897----------------------
7898
7899Here is an example of an INPUTRC file. This illustrates key binding,
7900variable assignment, and conditional syntax.
7901
7902 # This file controls the behaviour of line input editing for
7903 # programs that use the GNU Readline library. Existing
7904 # programs include FTP, Bash, and GDB.
7905 #
7906 # You can re-read the inputrc file with C-x C-r.
7907 # Lines beginning with '#' are comments.
7908 #
7909 # First, include any system-wide bindings and variable
7910 # assignments from /etc/Inputrc
7911 $include /etc/Inputrc
7912
7913 #
7914 # Set various bindings for emacs mode.
7915
7916 set editing-mode emacs
7917
7918 $if mode=emacs
7919
7920 Meta-Control-h: backward-kill-word Text after the function name is ignored
7921
7922 #
7923 # Arrow keys in keypad mode
7924 #
7925 #"\M-OD": backward-char
7926 #"\M-OC": forward-char
7927 #"\M-OA": previous-history
7928 #"\M-OB": next-history
7929 #
7930 # Arrow keys in ANSI mode
7931 #
7932 "\M-[D": backward-char
7933 "\M-[C": forward-char
7934 "\M-[A": previous-history
7935 "\M-[B": next-history
7936 #
7937 # Arrow keys in 8 bit keypad mode
7938 #
7939 #"\M-\C-OD": backward-char
7940 #"\M-\C-OC": forward-char
7941 #"\M-\C-OA": previous-history
7942 #"\M-\C-OB": next-history
7943 #
7944 # Arrow keys in 8 bit ANSI mode
7945 #
7946 #"\M-\C-[D": backward-char
7947 #"\M-\C-[C": forward-char
7948 #"\M-\C-[A": previous-history
7949 #"\M-\C-[B": next-history
7950
7951 C-q: quoted-insert
7952
7953 $endif
7954
7955 # An old-style binding. This happens to be the default.
7956 TAB: complete
7957
7958 # Macros that are convenient for shell interaction
7959 $if Bash
7960 # edit the path
7961 "\C-xp": "PATH=${PATH}\e\C-e\C-a\ef\C-f"
7962 # prepare to type a quoted word --
7963 # insert open and close double quotes
7964 # and move to just after the open quote
7965 "\C-x\"": "\"\"\C-b"
7966 # insert a backslash (testing backslash escapes
7967 # in sequences and macros)
7968 "\C-x\\": "\\"
7969 # Quote the current or previous word
7970 "\C-xq": "\eb\"\ef\""
7971 # Add a binding to refresh the line, which is unbound
7972 "\C-xr": redraw-current-line
7973 # Edit variable on current line.
7974 "\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y="
7975 $endif
7976
7977 # use a visible bell if one is available
7978 set bell-style visible
7979
7980 # don't strip characters to 7 bits when reading
7981 set input-meta on
7982
7983 # allow iso-latin1 characters to be inserted rather
7984 # than converted to prefix-meta sequences
7985 set convert-meta off
7986
7987 # display characters with the eighth bit set directly
7988 # rather than as meta-prefixed characters
7989 set output-meta on
7990
7991 # if there are more than 150 possible completions for
7992 # a word, ask the user if he wants to see all of them
7993 set completion-query-items 150
7994
7995 # For FTP
7996 $if Ftp
7997 "\C-xg": "get \M-?"
7998 "\C-xt": "put \M-?"
7999 "\M-.": yank-last-arg
8000 $endif
8001
8002\1f
8003File: bash.info, Node: Bindable Readline Commands, Next: Readline vi Mode, Prev: Readline Init File, Up: Command Line Editing
8004
80058.4 Bindable Readline Commands
8006==============================
8007
8008* Menu:
8009
8010* Commands For Moving:: Moving about the line.
8011* Commands For History:: Getting at previous lines.
8012* Commands For Text:: Commands for changing text.
8013* Commands For Killing:: Commands for killing and yanking.
8014* Numeric Arguments:: Specifying numeric arguments, repeat counts.
8015* Commands For Completion:: Getting Readline to do the typing for you.
8016* Keyboard Macros:: Saving and re-executing typed characters
8017* Miscellaneous Commands:: Other miscellaneous commands.
8018
8019This section describes Readline commands that may be bound to key
8020sequences. You can list your key bindings by executing 'bind -P' or,
8021for a more terse format, suitable for an INPUTRC file, 'bind -p'.
8022(*Note Bash Builtins::.) Command names without an accompanying key
8023sequence are unbound by default.
8024
8025 In the following descriptions, "point" refers to the current cursor
8026position, and "mark" refers to a cursor position saved by the 'set-mark'
8027command. The text between the point and mark is referred to as the
8028"region".
8029
8030\1f
8031File: bash.info, Node: Commands For Moving, Next: Commands For History, Up: Bindable Readline Commands
8032
80338.4.1 Commands For Moving
8034-------------------------
8035
8036'beginning-of-line (C-a)'
8037 Move to the start of the current line.
8038
8039'end-of-line (C-e)'
8040 Move to the end of the line.
8041
8042'forward-char (C-f)'
8043 Move forward a character.
8044
8045'backward-char (C-b)'
8046 Move back a character.
8047
8048'forward-word (M-f)'
8049 Move forward to the end of the next word. Words are composed of
8050 letters and digits.
8051
8052'backward-word (M-b)'
8053 Move back to the start of the current or previous word. Words are
8054 composed of letters and digits.
8055
8056'shell-forward-word ()'
8057 Move forward to the end of the next word. Words are delimited by
8058 non-quoted shell metacharacters.
8059
8060'shell-backward-word ()'
8061 Move back to the start of the current or previous word. Words are
8062 delimited by non-quoted shell metacharacters.
8063
d233b485
CR
8064'previous-screen-line ()'
8065 Attempt to move point to the same physical screen column on the
8066 previous physical screen line. This will not have the desired
8067 effect if the current Readline line does not take up more than one
8068 physical line or if point is not greater than the length of the
8069 prompt plus the screen width.
8070
8071'next-screen-line ()'
8072 Attempt to move point to the same physical screen column on the
8073 next physical screen line. This will not have the desired effect
8074 if the current Readline line does not take up more than one
8075 physical line or if the length of the current Readline line is not
8076 greater than the length of the prompt plus the screen width.
8077
a0c0a00f
CR
8078'clear-screen (C-l)'
8079 Clear the screen and redraw the current line, leaving the current
8080 line at the top of the screen.
8081
8082'redraw-current-line ()'
8083 Refresh the current line. By default, this is unbound.
8084
8085\1f
8086File: bash.info, Node: Commands For History, Next: Commands For Text, Prev: Commands For Moving, Up: Bindable Readline Commands
8087
80888.4.2 Commands For Manipulating The History
8089-------------------------------------------
8090
8091'accept-line (Newline or Return)'
8092 Accept the line regardless of where the cursor is. If this line is
8093 non-empty, add it to the history list according to the setting of
8094 the 'HISTCONTROL' and 'HISTIGNORE' variables. If this line is a
8095 modified history line, then restore the history line to its
8096 original state.
8097
8098'previous-history (C-p)'
8099 Move 'back' through the history list, fetching the previous
8100 command.
8101
8102'next-history (C-n)'
8103 Move 'forward' through the history list, fetching the next command.
8104
8105'beginning-of-history (M-<)'
8106 Move to the first line in the history.
8107
8108'end-of-history (M->)'
8109 Move to the end of the input history, i.e., the line currently
8110 being entered.
8111
8112'reverse-search-history (C-r)'
8113 Search backward starting at the current line and moving 'up'
8114 through the history as necessary. This is an incremental search.
8115
8116'forward-search-history (C-s)'
8117 Search forward starting at the current line and moving 'down'
8118 through the history as necessary. This is an incremental search.
8119
8120'non-incremental-reverse-search-history (M-p)'
8121 Search backward starting at the current line and moving 'up'
8122 through the history as necessary using a non-incremental search for
8123 a string supplied by the user. The search string may match
8124 anywhere in a history line.
8125
8126'non-incremental-forward-search-history (M-n)'
8127 Search forward starting at the current line and moving 'down'
8128 through the history as necessary using a non-incremental search for
8129 a string supplied by the user. The search string may match
8130 anywhere in a history line.
8131
8132'history-search-forward ()'
8133 Search forward through the history for the string of characters
8134 between the start of the current line and the point. The search
8135 string must match at the beginning of a history line. This is a
8136 non-incremental search. By default, this command is unbound.
8137
8138'history-search-backward ()'
8139 Search backward through the history for the string of characters
8140 between the start of the current line and the point. The search
8141 string must match at the beginning of a history line. This is a
8142 non-incremental search. By default, this command is unbound.
8143
d233b485 8144'history-substring-search-forward ()'
a0c0a00f
CR
8145 Search forward through the history for the string of characters
8146 between the start of the current line and the point. The search
8147 string may match anywhere in a history line. This is a
8148 non-incremental search. By default, this command is unbound.
8149
d233b485 8150'history-substring-search-backward ()'
a0c0a00f
CR
8151 Search backward through the history for the string of characters
8152 between the start of the current line and the point. The search
8153 string may match anywhere in a history line. This is a
8154 non-incremental search. By default, this command is unbound.
8155
8156'yank-nth-arg (M-C-y)'
8157 Insert the first argument to the previous command (usually the
8158 second word on the previous line) at point. With an argument N,
8159 insert the Nth word from the previous command (the words in the
8160 previous command begin with word 0). A negative argument inserts
8161 the Nth word from the end of the previous command. Once the
8162 argument N is computed, the argument is extracted as if the '!N'
8163 history expansion had been specified.
8164
8165'yank-last-arg (M-. or M-_)'
8166 Insert last argument to the previous command (the last word of the
8167 previous history entry). With a numeric argument, behave exactly
8168 like 'yank-nth-arg'. Successive calls to 'yank-last-arg' move back
8169 through the history list, inserting the last word (or the word
8170 specified by the argument to the first call) of each line in turn.
8171 Any numeric argument supplied to these successive calls determines
8172 the direction to move through the history. A negative argument
8173 switches the direction through the history (back or forward). The
8174 history expansion facilities are used to extract the last argument,
8175 as if the '!$' history expansion had been specified.
8176
8177\1f
8178File: bash.info, Node: Commands For Text, Next: Commands For Killing, Prev: Commands For History, Up: Bindable Readline Commands
8179
81808.4.3 Commands For Changing Text
8181--------------------------------
8182
8183'end-of-file (usually C-d)'
8184 The character indicating end-of-file as set, for example, by
8185 'stty'. If this character is read when there are no characters on
8186 the line, and point is at the beginning of the line, Readline
8187 interprets it as the end of input and returns EOF.
8188
8189'delete-char (C-d)'
8190 Delete the character at point. If this function is bound to the
8191 same character as the tty EOF character, as 'C-d' commonly is, see
8192 above for the effects.
8193
8194'backward-delete-char (Rubout)'
8195 Delete the character behind the cursor. A numeric argument means
8196 to kill the characters instead of deleting them.
8197
8198'forward-backward-delete-char ()'
8199 Delete the character under the cursor, unless the cursor is at the
8200 end of the line, in which case the character behind the cursor is
8201 deleted. By default, this is not bound to a key.
8202
8203'quoted-insert (C-q or C-v)'
8204 Add the next character typed to the line verbatim. This is how to
8205 insert key sequences like 'C-q', for example.
8206
8207'self-insert (a, b, A, 1, !, ...)'
8208 Insert yourself.
8209
8210'bracketed-paste-begin ()'
8211 This function is intended to be bound to the "bracketed paste"
8212 escape sequence sent by some terminals, and such a binding is
8213 assigned by default. It allows Readline to insert the pasted text
8214 as a single unit without treating each character as if it had been
8215 read from the keyboard. The characters are inserted as if each one
d233b485 8216 was bound to 'self-insert' instead of executing any editing
a0c0a00f
CR
8217 commands.
8218
8219'transpose-chars (C-t)'
8220 Drag the character before the cursor forward over the character at
8221 the cursor, moving the cursor forward as well. If the insertion
8222 point is at the end of the line, then this transposes the last two
8223 characters of the line. Negative arguments have no effect.
8224
8225'transpose-words (M-t)'
8226 Drag the word before point past the word after point, moving point
8227 past that word as well. If the insertion point is at the end of
8228 the line, this transposes the last two words on the line.
8229
8230'upcase-word (M-u)'
8231 Uppercase the current (or following) word. With a negative
8232 argument, uppercase the previous word, but do not move the cursor.
8233
8234'downcase-word (M-l)'
8235 Lowercase the current (or following) word. With a negative
8236 argument, lowercase the previous word, but do not move the cursor.
8237
8238'capitalize-word (M-c)'
8239 Capitalize the current (or following) word. With a negative
8240 argument, capitalize the previous word, but do not move the cursor.
8241
8242'overwrite-mode ()'
8243 Toggle overwrite mode. With an explicit positive numeric argument,
8244 switches to overwrite mode. With an explicit non-positive numeric
8245 argument, switches to insert mode. This command affects only
8246 'emacs' mode; 'vi' mode does overwrite differently. Each call to
8247 'readline()' starts in insert mode.
8248
8249 In overwrite mode, characters bound to 'self-insert' replace the
8250 text at point rather than pushing the text to the right.
8251 Characters bound to 'backward-delete-char' replace the character
8252 before point with a space.
8253
8254 By default, this command is unbound.
8255
8256\1f
8257File: bash.info, Node: Commands For Killing, Next: Numeric Arguments, Prev: Commands For Text, Up: Bindable Readline Commands
8258
82598.4.4 Killing And Yanking
8260-------------------------
8261
8262'kill-line (C-k)'
8263 Kill the text from point to the end of the line.
8264
8265'backward-kill-line (C-x Rubout)'
8266 Kill backward from the cursor to the beginning of the current line.
8267
8268'unix-line-discard (C-u)'
8269 Kill backward from the cursor to the beginning of the current line.
8270
8271'kill-whole-line ()'
8272 Kill all characters on the current line, no matter where point is.
8273 By default, this is unbound.
8274
8275'kill-word (M-d)'
8276 Kill from point to the end of the current word, or if between
8277 words, to the end of the next word. Word boundaries are the same
8278 as 'forward-word'.
8279
8280'backward-kill-word (M-<DEL>)'
8281 Kill the word behind point. Word boundaries are the same as
8282 'backward-word'.
8283
8284'shell-kill-word ()'
8285 Kill from point to the end of the current word, or if between
8286 words, to the end of the next word. Word boundaries are the same
8287 as 'shell-forward-word'.
8288
8289'shell-backward-kill-word ()'
8290 Kill the word behind point. Word boundaries are the same as
8291 'shell-backward-word'.
8292
8293'unix-word-rubout (C-w)'
8294 Kill the word behind point, using white space as a word boundary.
8295 The killed text is saved on the kill-ring.
8296
8297'unix-filename-rubout ()'
8298 Kill the word behind point, using white space and the slash
8299 character as the word boundaries. The killed text is saved on the
8300 kill-ring.
8301
8302'delete-horizontal-space ()'
8303 Delete all spaces and tabs around point. By default, this is
8304 unbound.
8305
8306'kill-region ()'
8307 Kill the text in the current region. By default, this command is
8308 unbound.
8309
8310'copy-region-as-kill ()'
8311 Copy the text in the region to the kill buffer, so it can be yanked
8312 right away. By default, this command is unbound.
8313
8314'copy-backward-word ()'
8315 Copy the word before point to the kill buffer. The word boundaries
8316 are the same as 'backward-word'. By default, this command is
8317 unbound.
8318
8319'copy-forward-word ()'
8320 Copy the word following point to the kill buffer. The word
8321 boundaries are the same as 'forward-word'. By default, this
8322 command is unbound.
8323
8324'yank (C-y)'
8325 Yank the top of the kill ring into the buffer at point.
8326
8327'yank-pop (M-y)'
8328 Rotate the kill-ring, and yank the new top. You can only do this
8329 if the prior command is 'yank' or 'yank-pop'.
8330
8331\1f
8332File: bash.info, Node: Numeric Arguments, Next: Commands For Completion, Prev: Commands For Killing, Up: Bindable Readline Commands
8333
83348.4.5 Specifying Numeric Arguments
8335----------------------------------
8336
8337'digit-argument (M-0, M-1, ... M--)'
8338 Add this digit to the argument already accumulating, or start a new
8339 argument. 'M--' starts a negative argument.
8340
8341'universal-argument ()'
8342 This is another way to specify an argument. If this command is
8343 followed by one or more digits, optionally with a leading minus
8344 sign, those digits define the argument. If the command is followed
8345 by digits, executing 'universal-argument' again ends the numeric
8346 argument, but is otherwise ignored. As a special case, if this
8347 command is immediately followed by a character that is neither a
8348 digit nor minus sign, the argument count for the next command is
8349 multiplied by four. The argument count is initially one, so
8350 executing this function the first time makes the argument count
8351 four, a second time makes the argument count sixteen, and so on.
8352 By default, this is not bound to a key.
8353
8354\1f
8355File: bash.info, Node: Commands For Completion, Next: Keyboard Macros, Prev: Numeric Arguments, Up: Bindable Readline Commands
8356
83578.4.6 Letting Readline Type For You
8358-----------------------------------
8359
8360'complete (<TAB>)'
8361 Attempt to perform completion on the text before point. The actual
8362 completion performed is application-specific. Bash attempts
8363 completion treating the text as a variable (if the text begins with
8364 '$'), username (if the text begins with '~'), hostname (if the text
8365 begins with '@'), or command (including aliases and functions) in
8366 turn. If none of these produces a match, filename completion is
8367 attempted.
8368
8369'possible-completions (M-?)'
8370 List the possible completions of the text before point. When
8371 displaying completions, Readline sets the number of columns used
8372 for display to the value of 'completion-display-width', the value
8373 of the environment variable 'COLUMNS', or the screen width, in that
8374 order.
8375
8376'insert-completions (M-*)'
8377 Insert all completions of the text before point that would have
8378 been generated by 'possible-completions'.
8379
8380'menu-complete ()'
8381 Similar to 'complete', but replaces the word to be completed with a
8382 single match from the list of possible completions. Repeated
8383 execution of 'menu-complete' steps through the list of possible
8384 completions, inserting each match in turn. At the end of the list
8385 of completions, the bell is rung (subject to the setting of
8386 'bell-style') and the original text is restored. An argument of N
8387 moves N positions forward in the list of matches; a negative
8388 argument may be used to move backward through the list. This
8389 command is intended to be bound to <TAB>, but is unbound by
8390 default.
8391
8392'menu-complete-backward ()'
8393 Identical to 'menu-complete', but moves backward through the list
8394 of possible completions, as if 'menu-complete' had been given a
8395 negative argument.
8396
8397'delete-char-or-list ()'
8398 Deletes the character under the cursor if not at the beginning or
8399 end of the line (like 'delete-char'). If at the end of the line,
8400 behaves identically to 'possible-completions'. This command is
8401 unbound by default.
8402
8403'complete-filename (M-/)'
8404 Attempt filename completion on the text before point.
8405
8406'possible-filename-completions (C-x /)'
8407 List the possible completions of the text before point, treating it
8408 as a filename.
8409
8410'complete-username (M-~)'
8411 Attempt completion on the text before point, treating it as a
8412 username.
8413
8414'possible-username-completions (C-x ~)'
8415 List the possible completions of the text before point, treating it
8416 as a username.
8417
8418'complete-variable (M-$)'
8419 Attempt completion on the text before point, treating it as a shell
8420 variable.
8421
8422'possible-variable-completions (C-x $)'
8423 List the possible completions of the text before point, treating it
8424 as a shell variable.
8425
8426'complete-hostname (M-@)'
8427 Attempt completion on the text before point, treating it as a
8428 hostname.
8429
8430'possible-hostname-completions (C-x @)'
8431 List the possible completions of the text before point, treating it
8432 as a hostname.
8433
8434'complete-command (M-!)'
8435 Attempt completion on the text before point, treating it as a
8436 command name. Command completion attempts to match the text
8437 against aliases, reserved words, shell functions, shell builtins,
8438 and finally executable filenames, in that order.
8439
8440'possible-command-completions (C-x !)'
8441 List the possible completions of the text before point, treating it
8442 as a command name.
8443
8444'dynamic-complete-history (M-<TAB>)'
8445 Attempt completion on the text before point, comparing the text
8446 against lines from the history list for possible completion
8447 matches.
8448
8449'dabbrev-expand ()'
8450 Attempt menu completion on the text before point, comparing the
8451 text against lines from the history list for possible completion
8452 matches.
8453
8454'complete-into-braces (M-{)'
8455 Perform filename completion and insert the list of possible
8456 completions enclosed within braces so the list is available to the
8457 shell (*note Brace Expansion::).
8458
8459\1f
8460File: bash.info, Node: Keyboard Macros, Next: Miscellaneous Commands, Prev: Commands For Completion, Up: Bindable Readline Commands
8461
84628.4.7 Keyboard Macros
8463---------------------
8464
8465'start-kbd-macro (C-x ()'
8466 Begin saving the characters typed into the current keyboard macro.
8467
8468'end-kbd-macro (C-x ))'
8469 Stop saving the characters typed into the current keyboard macro
8470 and save the definition.
8471
8472'call-last-kbd-macro (C-x e)'
8473 Re-execute the last keyboard macro defined, by making the
8474 characters in the macro appear as if typed at the keyboard.
8475
8476'print-last-kbd-macro ()'
8477 Print the last keboard macro defined in a format suitable for the
8478 INPUTRC file.
8479
8480\1f
8481File: bash.info, Node: Miscellaneous Commands, Prev: Keyboard Macros, Up: Bindable Readline Commands
8482
84838.4.8 Some Miscellaneous Commands
8484---------------------------------
8485
8486're-read-init-file (C-x C-r)'
8487 Read in the contents of the INPUTRC file, and incorporate any
8488 bindings or variable assignments found there.
8489
8490'abort (C-g)'
8491 Abort the current editing command and ring the terminal's bell
8492 (subject to the setting of 'bell-style').
8493
d233b485
CR
8494'do-lowercase-version (M-A, M-B, M-X, ...)'
8495 If the metafied character X is upper case, run the command that is
8496 bound to the corresponding metafied lower case character. The
8497 behavior is undefined if X is already lower case.
a0c0a00f
CR
8498
8499'prefix-meta (<ESC>)'
8500 Metafy the next character typed. This is for keyboards without a
8501 meta key. Typing '<ESC> f' is equivalent to typing 'M-f'.
8502
8503'undo (C-_ or C-x C-u)'
8504 Incremental undo, separately remembered for each line.
8505
8506'revert-line (M-r)'
8507 Undo all changes made to this line. This is like executing the
8508 'undo' command enough times to get back to the beginning.
8509
8510'tilde-expand (M-&)'
8511 Perform tilde expansion on the current word.
8512
8513'set-mark (C-@)'
8514 Set the mark to the point. If a numeric argument is supplied, the
8515 mark is set to that position.
8516
8517'exchange-point-and-mark (C-x C-x)'
8518 Swap the point with the mark. The current cursor position is set
8519 to the saved position, and the old cursor position is saved as the
8520 mark.
8521
8522'character-search (C-])'
8523 A character is read and point is moved to the next occurrence of
8524 that character. A negative count searches for previous
8525 occurrences.
8526
8527'character-search-backward (M-C-])'
8528 A character is read and point is moved to the previous occurrence
8529 of that character. A negative count searches for subsequent
8530 occurrences.
8531
8532'skip-csi-sequence ()'
8533 Read enough characters to consume a multi-key sequence such as
8534 those defined for keys like Home and End. Such sequences begin
8535 with a Control Sequence Indicator (CSI), usually ESC-[. If this
8536 sequence is bound to "\e[", keys producing such sequences will have
8537 no effect unless explicitly bound to a readline command, instead of
8538 inserting stray characters into the editing buffer. This is
8539 unbound by default, but usually bound to ESC-[.
8540
8541'insert-comment (M-#)'
8542 Without a numeric argument, the value of the 'comment-begin'
8543 variable is inserted at the beginning of the current line. If a
8544 numeric argument is supplied, this command acts as a toggle: if the
8545 characters at the beginning of the line do not match the value of
8546 'comment-begin', the value is inserted, otherwise the characters in
8547 'comment-begin' are deleted from the beginning of the line. In
8548 either case, the line is accepted as if a newline had been typed.
8549 The default value of 'comment-begin' causes this command to make
8550 the current line a shell comment. If a numeric argument causes the
8551 comment character to be removed, the line will be executed by the
8552 shell.
8553
8554'dump-functions ()'
8555 Print all of the functions and their key bindings to the Readline
8556 output stream. If a numeric argument is supplied, the output is
8557 formatted in such a way that it can be made part of an INPUTRC
8558 file. This command is unbound by default.
8559
8560'dump-variables ()'
8561 Print all of the settable variables and their values to the
8562 Readline output stream. If a numeric argument is supplied, the
8563 output is formatted in such a way that it can be made part of an
8564 INPUTRC file. This command is unbound by default.
8565
8566'dump-macros ()'
8567 Print all of the Readline key sequences bound to macros and the
8568 strings they output. If a numeric argument is supplied, the output
8569 is formatted in such a way that it can be made part of an INPUTRC
8570 file. This command is unbound by default.
8571
8572'glob-complete-word (M-g)'
8573 The word before point is treated as a pattern for pathname
8574 expansion, with an asterisk implicitly appended. This pattern is
8575 used to generate a list of matching file names for possible
8576 completions.
8577
8578'glob-expand-word (C-x *)'
8579 The word before point is treated as a pattern for pathname
8580 expansion, and the list of matching file names is inserted,
8581 replacing the word. If a numeric argument is supplied, a '*' is
8582 appended before pathname expansion.
8583
8584'glob-list-expansions (C-x g)'
8585 The list of expansions that would have been generated by
8586 'glob-expand-word' is displayed, and the line is redrawn. If a
8587 numeric argument is supplied, a '*' is appended before pathname
8588 expansion.
8589
8590'display-shell-version (C-x C-v)'
8591 Display version information about the current instance of Bash.
8592
8593'shell-expand-line (M-C-e)'
8594 Expand the line as the shell does. This performs alias and history
8595 expansion as well as all of the shell word expansions (*note Shell
8596 Expansions::).
8597
8598'history-expand-line (M-^)'
8599 Perform history expansion on the current line.
8600
8601'magic-space ()'
8602 Perform history expansion on the current line and insert a space
8603 (*note History Interaction::).
8604
8605'alias-expand-line ()'
8606 Perform alias expansion on the current line (*note Aliases::).
8607
8608'history-and-alias-expand-line ()'
8609 Perform history and alias expansion on the current line.
8610
8611'insert-last-argument (M-. or M-_)'
8612 A synonym for 'yank-last-arg'.
8613
8614'operate-and-get-next (C-o)'
8615 Accept the current line for execution and fetch the next line
d233b485
CR
8616 relative to the current line from the history for editing. A
8617 numeric argument, if supplied, specifies the history entry to use
8618 instead of the current line.
a0c0a00f 8619
d233b485 8620'edit-and-execute-command (C-x C-e)'
a0c0a00f
CR
8621 Invoke an editor on the current command line, and execute the
8622 result as shell commands. Bash attempts to invoke '$VISUAL',
8623 '$EDITOR', and 'emacs' as the editor, in that order.
8624
8625\1f
8626File: bash.info, Node: Readline vi Mode, Next: Programmable Completion, Prev: Bindable Readline Commands, Up: Command Line Editing
8627
86288.5 Readline vi Mode
8629====================
8630
8631While the Readline library does not have a full set of 'vi' editing
8632functions, it does contain enough to allow simple editing of the line.
8633The Readline 'vi' mode behaves as specified in the POSIX standard.
8634
8635 In order to switch interactively between 'emacs' and 'vi' editing
8636modes, use the 'set -o emacs' and 'set -o vi' commands (*note The Set
8637Builtin::). The Readline default is 'emacs' mode.
8638
8639 When you enter a line in 'vi' mode, you are already placed in
8640'insertion' mode, as if you had typed an 'i'. Pressing <ESC> switches
8641you into 'command' mode, where you can edit the text of the line with
8642the standard 'vi' movement keys, move to previous history lines with 'k'
8643and subsequent lines with 'j', and so forth.
8644
8645\1f
8646File: bash.info, Node: Programmable Completion, Next: Programmable Completion Builtins, Prev: Readline vi Mode, Up: Command Line Editing
8647
86488.6 Programmable Completion
8649===========================
8650
8651When word completion is attempted for an argument to a command for which
8652a completion specification (a COMPSPEC) has been defined using the
8653'complete' builtin (*note Programmable Completion Builtins::), the
8654programmable completion facilities are invoked.
8655
8656 First, the command name is identified. If a compspec has been
8657defined for that command, the compspec is used to generate the list of
8658possible completions for the word. If the command word is the empty
8659string (completion attempted at the beginning of an empty line), any
8660compspec defined with the '-E' option to 'complete' is used. If the
8661command word is a full pathname, a compspec for the full pathname is
8662searched for first. If no compspec is found for the full pathname, an
8663attempt is made to find a compspec for the portion following the final
8664slash. If those searches do not result in a compspec, any compspec
d233b485
CR
8665defined with the '-D' option to 'complete' is used as the default. If
8666there is no default compspec, Bash attempts alias expansion on the
8667command word as a final resort, and attempts to find a compspec for the
8668command word from any successful expansion
a0c0a00f
CR
8669
8670 Once a compspec has been found, it is used to generate the list of
8671matching words. If a compspec is not found, the default Bash completion
8672described above (*note Commands For Completion::) is performed.
8673
8674 First, the actions specified by the compspec are used. Only matches
8675which are prefixed by the word being completed are returned. When the
8676'-f' or '-d' option is used for filename or directory name completion,
8677the shell variable 'FIGNORE' is used to filter the matches. *Note Bash
8678Variables::, for a description of 'FIGNORE'.
8679
8680 Any completions specified by a filename expansion pattern to the '-G'
8681option are generated next. The words generated by the pattern need not
8682match the word being completed. The 'GLOBIGNORE' shell variable is not
8683used to filter the matches, but the 'FIGNORE' shell variable is used.
8684
8685 Next, the string specified as the argument to the '-W' option is
8686considered. The string is first split using the characters in the 'IFS'
d233b485
CR
8687special variable as delimiters. Shell quoting is honored within the
8688string, in order to provide a mechanism for the words to contain shell
8689metacharacters or characters in the value of 'IFS'. Each word is then
8690expanded using brace expansion, tilde expansion, parameter and variable
8691expansion, command substitution, and arithmetic expansion, as described
8692above (*note Shell Expansions::). The results are split using the rules
8693described above (*note Word Splitting::). The results of the expansion
8694are prefix-matched against the word being completed, and the matching
8695words become the possible completions.
a0c0a00f
CR
8696
8697 After these matches have been generated, any shell function or
8698command specified with the '-F' and '-C' options is invoked. When the
8699command or function is invoked, the 'COMP_LINE', 'COMP_POINT',
8700'COMP_KEY', and 'COMP_TYPE' variables are assigned values as described
8701above (*note Bash Variables::). If a shell function is being invoked,
8702the 'COMP_WORDS' and 'COMP_CWORD' variables are also set. When the
8703function or command is invoked, the first argument ($1) is the name of
8704the command whose arguments are being completed, the second argument
8705($2) is the word being completed, and the third argument ($3) is the
8706word preceding the word being completed on the current command line. No
8707filtering of the generated completions against the word being completed
8708is performed; the function or command has complete freedom in generating
8709the matches.
8710
8711 Any function specified with '-F' is invoked first. The function may
8712use any of the shell facilities, including the 'compgen' and 'compopt'
8713builtins described below (*note Programmable Completion Builtins::), to
8714generate the matches. It must put the possible completions in the
8715'COMPREPLY' array variable, one per array element.
8716
8717 Next, any command specified with the '-C' option is invoked in an
8718environment equivalent to command substitution. It should print a list
8719of completions, one per line, to the standard output. Backslash may be
8720used to escape a newline, if necessary.
8721
8722 After all of the possible completions are generated, any filter
8723specified with the '-X' option is applied to the list. The filter is a
8724pattern as used for pathname expansion; a '&' in the pattern is replaced
8725with the text of the word being completed. A literal '&' may be escaped
8726with a backslash; the backslash is removed before attempting a match.
8727Any completion that matches the pattern will be removed from the list.
8728A leading '!' negates the pattern; in this case any completion not
8729matching the pattern will be removed. If the 'nocasematch' shell option
8730(see the description of 'shopt' in *note The Shopt Builtin::) is
8731enabled, the match is performed without regard to the case of alphabetic
8732characters.
8733
8734 Finally, any prefix and suffix specified with the '-P' and '-S'
8735options are added to each member of the completion list, and the result
8736is returned to the Readline completion code as the list of possible
8737completions.
8738
8739 If the previously-applied actions do not generate any matches, and
8740the '-o dirnames' option was supplied to 'complete' when the compspec
8741was defined, directory name completion is attempted.
8742
8743 If the '-o plusdirs' option was supplied to 'complete' when the
8744compspec was defined, directory name completion is attempted and any
8745matches are added to the results of the other actions.
8746
8747 By default, if a compspec is found, whatever it generates is returned
8748to the completion code as the full set of possible completions. The
8749default Bash completions are not attempted, and the Readline default of
8750filename completion is disabled. If the '-o bashdefault' option was
8751supplied to 'complete' when the compspec was defined, the default Bash
8752completions are attempted if the compspec generates no matches. If the
8753'-o default' option was supplied to 'complete' when the compspec was
8754defined, Readline's default completion will be performed if the compspec
8755(and, if attempted, the default Bash completions) generate no matches.
8756
8757 When a compspec indicates that directory name completion is desired,
8758the programmable completion functions force Readline to append a slash
8759to completed names which are symbolic links to directories, subject to
8760the value of the MARK-DIRECTORIES Readline variable, regardless of the
8761setting of the MARK-SYMLINKED-DIRECTORIES Readline variable.
8762
8763 There is some support for dynamically modifying completions. This is
8764most useful when used in combination with a default completion specified
8765with '-D'. It's possible for shell functions executed as completion
8766handlers to indicate that completion should be retried by returning an
8767exit status of 124. If a shell function returns 124, and changes the
8768compspec associated with the command on which completion is being
8769attempted (supplied as the first argument when the function is
8770executed), programmable completion restarts from the beginning, with an
8771attempt to find a new compspec for that command. This allows a set of
8772completions to be built dynamically as completion is attempted, rather
8773than being loaded all at once.
8774
8775 For instance, assuming that there is a library of compspecs, each
8776kept in a file corresponding to the name of the command, the following
8777default completion function would load completions dynamically:
8778
8779 _completion_loader()
8780 {
8781 . "/etc/bash_completion.d/$1.sh" >/dev/null 2>&1 && return 124
8782 }
8783 complete -D -F _completion_loader -o bashdefault -o default
8784
8785\1f
8786File: bash.info, Node: Programmable Completion Builtins, Next: A Programmable Completion Example, Prev: Programmable Completion, Up: Command Line Editing
8787
87888.7 Programmable Completion Builtins
8789====================================
8790
8791Three builtin commands are available to manipulate the programmable
8792completion facilities: one to specify how the arguments to a particular
8793command are to be completed, and two to modify the completion as it is
8794happening.
8795
8796'compgen'
8797 compgen [OPTION] [WORD]
8798
8799 Generate possible completion matches for WORD according to the
8800 OPTIONs, which may be any option accepted by the 'complete' builtin
8801 with the exception of '-p' and '-r', and write the matches to the
8802 standard output. When using the '-F' or '-C' options, the various
8803 shell variables set by the programmable completion facilities,
8804 while available, will not have useful values.
8805
8806 The matches will be generated in the same way as if the
8807 programmable completion code had generated them directly from a
8808 completion specification with the same flags. If WORD is
8809 specified, only those completions matching WORD will be displayed.
8810
8811 The return value is true unless an invalid option is supplied, or
8812 no matches were generated.
8813
8814'complete'
d233b485
CR
8815 complete [-abcdefgjksuv] [-o COMP-OPTION] [-DEI] [-A ACTION] [-G GLOBPAT]
8816 [-W WORDLIST] [-F FUNCTION] [-C COMMAND] [-X FILTERPAT]
a0c0a00f 8817 [-P PREFIX] [-S SUFFIX] NAME [NAME ...]
d233b485 8818 complete -pr [-DEI] [NAME ...]
a0c0a00f
CR
8819
8820 Specify how arguments to each NAME should be completed. If the
8821 '-p' option is supplied, or if no options are supplied, existing
8822 completion specifications are printed in a way that allows them to
8823 be reused as input. The '-r' option removes a completion
8824 specification for each NAME, or, if no NAMEs are supplied, all
d233b485
CR
8825 completion specifications. The '-D' option indicates that other
8826 supplied options and actions should apply to the "default" command
a0c0a00f
CR
8827 completion; that is, completion attempted on a command for which no
8828 completion has previously been defined. The '-E' option indicates
d233b485 8829 that other supplied options and actions should apply to "empty"
a0c0a00f 8830 command completion; that is, completion attempted on a blank line.
d233b485
CR
8831 The '-I' option indicates that other supplied options and actions
8832 should apply to completion on the inital non-assignment word on the
8833 line, or after a command delimiter such as ';' or '|', which is
8834 usually command name completion. If multiple options are supplied,
8835 the '-D' option takes precedence over '-E', and both take
8836 precedence over '-I'. If any of '-D', '-E', or '-I' are supplied,
8837 any other NAME arguments are ignored; these completions only apply
8838 to the case specified by the option.
a0c0a00f
CR
8839
8840 The process of applying these completion specifications when word
8841 completion is attempted is described above (*note Programmable
d233b485 8842 Completion::).
a0c0a00f
CR
8843
8844 Other options, if specified, have the following meanings. The
8845 arguments to the '-G', '-W', and '-X' options (and, if necessary,
8846 the '-P' and '-S' options) should be quoted to protect them from
8847 expansion before the 'complete' builtin is invoked.
8848
8849 '-o COMP-OPTION'
8850 The COMP-OPTION controls several aspects of the compspec's
8851 behavior beyond the simple generation of completions.
8852 COMP-OPTION may be one of:
8853
8854 'bashdefault'
8855 Perform the rest of the default Bash completions if the
8856 compspec generates no matches.
8857
8858 'default'
8859 Use Readline's default filename completion if the
8860 compspec generates no matches.
8861
8862 'dirnames'
8863 Perform directory name completion if the compspec
8864 generates no matches.
8865
8866 'filenames'
8867 Tell Readline that the compspec generates filenames, so
8868 it can perform any filename-specific processing (like
d233b485 8869 adding a slash to directory names, quoting special
a0c0a00f
CR
8870 characters, or suppressing trailing spaces). This option
8871 is intended to be used with shell functions specified
8872 with '-F'.
8873
8874 'noquote'
8875 Tell Readline not to quote the completed words if they
8876 are filenames (quoting filenames is the default).
8877
8878 'nosort'
8879 Tell Readline not to sort the list of possible
8880 completions alphabetically.
8881
8882 'nospace'
8883 Tell Readline not to append a space (the default) to
8884 words completed at the end of the line.
8885
8886 'plusdirs'
8887 After any matches defined by the compspec are generated,
8888 directory name completion is attempted and any matches
8889 are added to the results of the other actions.
8890
8891 '-A ACTION'
8892 The ACTION may be one of the following to generate a list of
8893 possible completions:
8894
8895 'alias'
8896 Alias names. May also be specified as '-a'.
8897
8898 'arrayvar'
8899 Array variable names.
8900
8901 'binding'
8902 Readline key binding names (*note Bindable Readline
8903 Commands::).
8904
8905 'builtin'
8906 Names of shell builtin commands. May also be specified
8907 as '-b'.
8908
8909 'command'
8910 Command names. May also be specified as '-c'.
8911
8912 'directory'
8913 Directory names. May also be specified as '-d'.
8914
8915 'disabled'
8916 Names of disabled shell builtins.
8917
8918 'enabled'
8919 Names of enabled shell builtins.
8920
8921 'export'
8922 Names of exported shell variables. May also be specified
8923 as '-e'.
8924
8925 'file'
8926 File names. May also be specified as '-f'.
8927
8928 'function'
8929 Names of shell functions.
8930
8931 'group'
8932 Group names. May also be specified as '-g'.
8933
8934 'helptopic'
8935 Help topics as accepted by the 'help' builtin (*note Bash
8936 Builtins::).
8937
8938 'hostname'
8939 Hostnames, as taken from the file specified by the
8940 'HOSTFILE' shell variable (*note Bash Variables::).
8941
8942 'job'
8943 Job names, if job control is active. May also be
8944 specified as '-j'.
8945
8946 'keyword'
8947 Shell reserved words. May also be specified as '-k'.
8948
8949 'running'
8950 Names of running jobs, if job control is active.
8951
8952 'service'
8953 Service names. May also be specified as '-s'.
8954
8955 'setopt'
8956 Valid arguments for the '-o' option to the 'set' builtin
8957 (*note The Set Builtin::).
8958
8959 'shopt'
8960 Shell option names as accepted by the 'shopt' builtin
8961 (*note Bash Builtins::).
8962
8963 'signal'
8964 Signal names.
8965
8966 'stopped'
8967 Names of stopped jobs, if job control is active.
8968
8969 'user'
8970 User names. May also be specified as '-u'.
8971
8972 'variable'
8973 Names of all shell variables. May also be specified as
8974 '-v'.
8975
8976 '-C COMMAND'
8977 COMMAND is executed in a subshell environment, and its output
8978 is used as the possible completions.
8979
8980 '-F FUNCTION'
8981 The shell function FUNCTION is executed in the current shell
8982 environment. When it is executed, $1 is the name of the
8983 command whose arguments are being completed, $2 is the word
8984 being completed, and $3 is the word preceding the word being
8985 completed, as described above (*note Programmable
8986 Completion::). When it finishes, the possible completions are
8987 retrieved from the value of the 'COMPREPLY' array variable.
8988
8989 '-G GLOBPAT'
8990 The filename expansion pattern GLOBPAT is expanded to generate
8991 the possible completions.
8992
8993 '-P PREFIX'
8994 PREFIX is added at the beginning of each possible completion
8995 after all other options have been applied.
8996
8997 '-S SUFFIX'
8998 SUFFIX is appended to each possible completion after all other
8999 options have been applied.
9000
9001 '-W WORDLIST'
9002 The WORDLIST is split using the characters in the 'IFS'
9003 special variable as delimiters, and each resultant word is
9004 expanded. The possible completions are the members of the
9005 resultant list which match the word being completed.
9006
9007 '-X FILTERPAT'
9008 FILTERPAT is a pattern as used for filename expansion. It is
9009 applied to the list of possible completions generated by the
9010 preceding options and arguments, and each completion matching
9011 FILTERPAT is removed from the list. A leading '!' in
9012 FILTERPAT negates the pattern; in this case, any completion
9013 not matching FILTERPAT is removed.
9014
9015 The return value is true unless an invalid option is supplied, an
9016 option other than '-p' or '-r' is supplied without a NAME argument,
9017 an attempt is made to remove a completion specification for a NAME
9018 for which no specification exists, or an error occurs adding a
9019 completion specification.
9020
9021'compopt'
d233b485 9022 compopt [-o OPTION] [-DEI] [+o OPTION] [NAME]
a0c0a00f
CR
9023 Modify completion options for each NAME according to the OPTIONs,
9024 or for the currently-executing completion if no NAMEs are supplied.
9025 If no OPTIONs are given, display the completion options for each
9026 NAME or the current completion. The possible values of OPTION are
9027 those valid for the 'complete' builtin described above. The '-D'
d233b485 9028 option indicates that other supplied options should apply to the
a0c0a00f
CR
9029 "default" command completion; that is, completion attempted on a
9030 command for which no completion has previously been defined. The
d233b485 9031 '-E' option indicates that other supplied options should apply to
a0c0a00f 9032 "empty" command completion; that is, completion attempted on a
d233b485
CR
9033 blank line. The '-I' option indicates that other supplied options
9034 should apply to completion on the inital non-assignment word on the
9035 line, or after a command delimiter such as ';' or '|', which is
9036 usually command name completion.
a0c0a00f 9037
d233b485
CR
9038 If multiple options are supplied, the '-D' option takes precedence
9039 over '-E', and both take precedence over '-I'
a0c0a00f
CR
9040
9041 The return value is true unless an invalid option is supplied, an
9042 attempt is made to modify the options for a NAME for which no
9043 completion specification exists, or an output error occurs.
9044
9045\1f
9046File: bash.info, Node: A Programmable Completion Example, Prev: Programmable Completion Builtins, Up: Command Line Editing
9047
90488.8 A Programmable Completion Example
9049=====================================
9050
9051The most common way to obtain additional completion functionality beyond
9052the default actions 'complete' and 'compgen' provide is to use a shell
9053function and bind it to a particular command using 'complete -F'.
9054
9055 The following function provides completions for the 'cd' builtin. It
9056is a reasonably good example of what shell functions must do when used
d233b485
CR
9057for completion. This function uses the word passed as '$2' to determine
9058the directory name to complete. You can also use the 'COMP_WORDS' array
9059variable; the current word is indexed by the 'COMP_CWORD' variable.
a0c0a00f
CR
9060
9061 The function relies on the 'complete' and 'compgen' builtins to do
9062much of the work, adding only the things that the Bash 'cd' does beyond
9063accepting basic directory names: tilde expansion (*note Tilde
9064Expansion::), searching directories in $CDPATH, which is described above
9065(*note Bourne Shell Builtins::), and basic support for the 'cdable_vars'
9066shell option (*note The Shopt Builtin::). '_comp_cd' modifies the value
9067of IFS so that it contains only a newline to accommodate file names
9068containing spaces and tabs - 'compgen' prints the possible completions
9069it generates one per line.
9070
9071 Possible completions go into the COMPREPLY array variable, one
9072completion per array element. The programmable completion system
9073retrieves the completions from there when the function returns.
9074
9075 # A completion function for the cd builtin
9076 # based on the cd completion function from the bash_completion package
9077 _comp_cd()
9078 {
9079 local IFS=$' \t\n' # normalize IFS
9080 local cur _skipdot _cdpath
9081 local i j k
9082
d233b485 9083 # Tilde expansion, which also expands tilde to full pathname
a0c0a00f
CR
9084 case "$2" in
9085 \~*) eval cur="$2" ;;
9086 *) cur=$2 ;;
9087 esac
9088
9089 # no cdpath or absolute pathname -- straight directory completion
9090 if [[ -z "${CDPATH:-}" ]] || [[ "$cur" == @(./*|../*|/*) ]]; then
9091 # compgen prints paths one per line; could also use while loop
9092 IFS=$'\n'
9093 COMPREPLY=( $(compgen -d -- "$cur") )
9094 IFS=$' \t\n'
9095 # CDPATH+directories in the current directory if not in CDPATH
9096 else
9097 IFS=$'\n'
9098 _skipdot=false
9099 # preprocess CDPATH to convert null directory names to .
9100 _cdpath=${CDPATH/#:/.:}
9101 _cdpath=${_cdpath//::/:.:}
9102 _cdpath=${_cdpath/%:/:.}
9103 for i in ${_cdpath//:/$'\n'}; do
9104 if [[ $i -ef . ]]; then _skipdot=true; fi
9105 k="${#COMPREPLY[@]}"
9106 for j in $( compgen -d -- "$i/$cur" ); do
9107 COMPREPLY[k++]=${j#$i/} # cut off directory
9108 done
9109 done
9110 $_skipdot || COMPREPLY+=( $(compgen -d -- "$cur") )
9111 IFS=$' \t\n'
9112 fi
9113
9114 # variable names if appropriate shell option set and no completions
9115 if shopt -q cdable_vars && [[ ${#COMPREPLY[@]} -eq 0 ]]; then
9116 COMPREPLY=( $(compgen -v -- "$cur") )
9117 fi
9118
9119 return 0
9120 }
9121
9122 We install the completion function using the '-F' option to
9123'complete':
9124
9125 # Tell readline to quote appropriate and append slashes to directories;
9126 # use the bash default completion for other arguments
9127 complete -o filenames -o nospace -o bashdefault -F _comp_cd cd
9128
9129Since we'd like Bash and Readline to take care of some of the other
9130details for us, we use several other options to tell Bash and Readline
9131what to do. The '-o filenames' option tells Readline that the possible
9132completions should be treated as filenames, and quoted appropriately.
9133That option will also cause Readline to append a slash to filenames it
9134can determine are directories (which is why we might want to extend
9135'_comp_cd' to append a slash if we're using directories found via
9136CDPATH: Readline can't tell those completions are directories). The '-o
9137nospace' option tells Readline to not append a space character to the
9138directory name, in case we want to append to it. The '-o bashdefault'
9139option brings in the rest of the "Bash default" completions - possible
9140completion that Bash adds to the default Readline set. These include
9141things like command name completion, variable completion for words
9142beginning with '{', completions containing pathname expansion patterns
9143(*note Filename Expansion::), and so on.
9144
9145 Once installed using 'complete', '_comp_cd' will be called every time
9146we attempt word completion for a 'cd' command.
9147
9148 Many more examples - an extensive collection of completions for most
9149of the common GNU, Unix, and Linux commands - are available as part of
9150the bash_completion project. This is installed by default on many
9151GNU/Linux distributions. Originally written by Ian Macdonald, the
9152project now lives at <http://bash-completion.alioth.debian.org/>. There
9153are ports for other systems such as Solaris and Mac OS X.
9154
9155 An older version of the bash_completion package is distributed with
9156bash in the 'examples/complete' subdirectory.
9157
9158\1f
9159File: bash.info, Node: Using History Interactively, Next: Installing Bash, Prev: Command Line Editing, Up: Top
9160
91619 Using History Interactively
9162*****************************
9163
9164This chapter describes how to use the GNU History Library interactively,
9165from a user's standpoint. It should be considered a user's guide. For
9166information on using the GNU History Library in other programs, see the
9167GNU Readline Library Manual.
9168
9169* Menu:
9170
9171* Bash History Facilities:: How Bash lets you manipulate your command
9172 history.
9173* Bash History Builtins:: The Bash builtin commands that manipulate
9174 the command history.
9175* History Interaction:: What it feels like using History as a user.
9176
9177\1f
9178File: bash.info, Node: Bash History Facilities, Next: Bash History Builtins, Up: Using History Interactively
9179
91809.1 Bash History Facilities
9181===========================
9182
9183When the '-o history' option to the 'set' builtin is enabled (*note The
9184Set Builtin::), the shell provides access to the "command history", the
9185list of commands previously typed. The value of the 'HISTSIZE' shell
9186variable is used as the number of commands to save in a history list.
9187The text of the last '$HISTSIZE' commands (default 500) is saved. The
9188shell stores each command in the history list prior to parameter and
9189variable expansion but after history expansion is performed, subject to
9190the values of the shell variables 'HISTIGNORE' and 'HISTCONTROL'.
9191
9192 When the shell starts up, the history is initialized from the file
9193named by the 'HISTFILE' variable (default '~/.bash_history'). The file
9194named by the value of 'HISTFILE' is truncated, if necessary, to contain
9195no more than the number of lines specified by the value of the
9196'HISTFILESIZE' variable. When a shell with history enabled exits, the
9197last '$HISTSIZE' lines are copied from the history list to the file
9198named by '$HISTFILE'. If the 'histappend' shell option is set (*note
9199Bash Builtins::), the lines are appended to the history file, otherwise
9200the history file is overwritten. If 'HISTFILE' is unset, or if the
9201history file is unwritable, the history is not saved. After saving the
9202history, the history file is truncated to contain no more than
9203'$HISTFILESIZE' lines. If 'HISTFILESIZE' is unset, or set to null, a
9204non-numeric value, or a numeric value less than zero, the history file
9205is not truncated.
9206
9207 If the 'HISTTIMEFORMAT' is set, the time stamp information associated
9208with each history entry is written to the history file, marked with the
9209history comment character. When the history file is read, lines
9210beginning with the history comment character followed immediately by a
9211digit are interpreted as timestamps for the following history entry.
9212
9213 The builtin command 'fc' may be used to list or edit and re-execute a
9214portion of the history list. The 'history' builtin may be used to
9215display or modify the history list and manipulate the history file.
9216When using command-line editing, search commands are available in each
9217editing mode that provide access to the history list (*note Commands For
9218History::).
9219
9220 The shell allows control over which commands are saved on the history
9221list. The 'HISTCONTROL' and 'HISTIGNORE' variables may be set to cause
9222the shell to save only a subset of the commands entered. The 'cmdhist'
9223shell option, if enabled, causes the shell to attempt to save each line
9224of a multi-line command in the same history entry, adding semicolons
9225where necessary to preserve syntactic correctness. The 'lithist' shell
9226option causes the shell to save the command with embedded newlines
9227instead of semicolons. The 'shopt' builtin is used to set these
d233b485 9228options. *Note The Shopt Builtin::, for a description of 'shopt'.
a0c0a00f
CR
9229
9230\1f
9231File: bash.info, Node: Bash History Builtins, Next: History Interaction, Prev: Bash History Facilities, Up: Using History Interactively
9232
92339.2 Bash History Builtins
9234=========================
9235
9236Bash provides two builtin commands which manipulate the history list and
9237history file.
9238
9239'fc'
9240 fc [-e ENAME] [-lnr] [FIRST] [LAST]
9241 fc -s [PAT=REP] [COMMAND]
9242
9243 The first form selects a range of commands from FIRST to LAST from
9244 the history list and displays or edits and re-executes them. Both
9245 FIRST and LAST may be specified as a string (to locate the most
9246 recent command beginning with that string) or as a number (an index
9247 into the history list, where a negative number is used as an offset
d233b485
CR
9248 from the current command number). If LAST is not specified, it is
9249 set to FIRST. If FIRST is not specified, it is set to the previous
a0c0a00f
CR
9250 command for editing and -16 for listing. If the '-l' flag is
9251 given, the commands are listed on standard output. The '-n' flag
9252 suppresses the command numbers when listing. The '-r' flag
9253 reverses the order of the listing. Otherwise, the editor given by
9254 ENAME is invoked on a file containing those commands. If ENAME is
9255 not given, the value of the following variable expansion is used:
9256 '${FCEDIT:-${EDITOR:-vi}}'. This says to use the value of the
9257 'FCEDIT' variable if set, or the value of the 'EDITOR' variable if
9258 that is set, or 'vi' if neither is set. When editing is complete,
9259 the edited commands are echoed and executed.
9260
9261 In the second form, COMMAND is re-executed after each instance of
9262 PAT in the selected command is replaced by REP. COMMAND is
9263 intepreted the same as FIRST above.
9264
9265 A useful alias to use with the 'fc' command is 'r='fc -s'', so that
9266 typing 'r cc' runs the last command beginning with 'cc' and typing
9267 'r' re-executes the last command (*note Aliases::).
9268
9269'history'
9270 history [N]
9271 history -c
9272 history -d OFFSET
d233b485 9273 history -d START-END
a0c0a00f
CR
9274 history [-anrw] [FILENAME]
9275 history -ps ARG
9276
9277 With no options, display the history list with line numbers. Lines
9278 prefixed with a '*' have been modified. An argument of N lists
9279 only the last N lines. If the shell variable 'HISTTIMEFORMAT' is
9280 set and not null, it is used as a format string for STRFTIME to
9281 display the time stamp associated with each displayed history
9282 entry. No intervening blank is printed between the formatted time
9283 stamp and the history line.
9284
9285 Options, if supplied, have the following meanings:
9286
9287 '-c'
9288 Clear the history list. This may be combined with the other
9289 options to replace the history list completely.
9290
9291 '-d OFFSET'
d233b485
CR
9292 Delete the history entry at position OFFSET. If OFFSET is
9293 positive, it should be specified as it appears when the
9294 history is displayed. If OFFSET is negative, it is
9295 interpreted as relative to one greater than the last history
9296 position, so negative indices count back from the end of the
9297 history, and an index of '-1' refers to the current 'history
9298 -d' command.
9299
9300 '-d START-END'
9301 Delete the history entries between positions START and END,
9302 inclusive. Positive and negative values for START and END are
9303 interpreted as described above.
a0c0a00f
CR
9304
9305 '-a'
9306 Append the new history lines to the history file. These are
9307 history lines entered since the beginning of the current Bash
9308 session, but not already appended to the history file.
9309
9310 '-n'
9311 Append the history lines not already read from the history
9312 file to the current history list. These are lines appended to
9313 the history file since the beginning of the current Bash
9314 session.
9315
9316 '-r'
9317 Read the history file and append its contents to the history
9318 list.
9319
9320 '-w'
9321 Write out the current history list to the history file.
9322
9323 '-p'
9324 Perform history substitution on the ARGs and display the
9325 result on the standard output, without storing the results in
9326 the history list.
9327
9328 '-s'
9329 The ARGs are added to the end of the history list as a single
9330 entry.
9331
9332 When any of the '-w', '-r', '-a', or '-n' options is used, if
9333 FILENAME is given, then it is used as the history file. If not,
9334 then the value of the 'HISTFILE' variable is used.
9335
9336\1f
9337File: bash.info, Node: History Interaction, Prev: Bash History Builtins, Up: Using History Interactively
9338
93399.3 History Expansion
9340=====================
9341
9342The History library provides a history expansion feature that is similar
9343to the history expansion provided by 'csh'. This section describes the
9344syntax used to manipulate the history information.
9345
9346 History expansions introduce words from the history list into the
9347input stream, making it easy to repeat commands, insert the arguments to
9348a previous command into the current input line, or fix errors in
9349previous commands quickly.
9350
9351 History expansion is performed immediately after a complete line is
d233b485
CR
9352read, before the shell breaks it into words, and is performed on each
9353line individually. Bash attempts to inform the history expansion
9354functions about quoting still in effect from previous lines.
a0c0a00f
CR
9355
9356 History expansion takes place in two parts. The first is to
9357determine which line from the history list should be used during
9358substitution. The second is to select portions of that line for
9359inclusion into the current one. The line selected from the history is
9360called the "event", and the portions of that line that are acted upon
9361are called "words". Various "modifiers" are available to manipulate the
9362selected words. The line is broken into words in the same fashion that
9363Bash does, so that several words surrounded by quotes are considered one
9364word. History expansions are introduced by the appearance of the
d233b485
CR
9365history expansion character, which is '!' by default.
9366
9367 History expansion implements shell-like quoting conventions: a
9368backslash can be used to remove the special handling for the next
9369character; single quotes enclose verbatim sequences of characters, and
9370can be used to inhibit history expansion; and characters enclosed within
9371double quotes may be subject to history expansion, since backslash can
9372escape the history expansion character, but single quotes may not, since
9373they are not treated specially within double quotes.
9374
9375 When using the shell, only '\' and ''' may be used to escape the
9376history expansion character, but the history expansion character is also
9377treated as quoted if it immediately precedes the closing double quote in
9378a double-quoted string.
9379
9380 Several shell options settable with the 'shopt' builtin (*note The
9381Shopt Builtin::) may be used to tailor the behavior of history
9382expansion. If the 'histverify' shell option is enabled, and Readline is
9383being used, history substitutions are not immediately passed to the
9384shell parser. Instead, the expanded line is reloaded into the Readline
9385editing buffer for further modification. If Readline is being used, and
9386the 'histreedit' shell option is enabled, a failed history expansion
9387will be reloaded into the Readline editing buffer for correction. The
9388'-p' option to the 'history' builtin command may be used to see what a
a0c0a00f
CR
9389history expansion will do before using it. The '-s' option to the
9390'history' builtin may be used to add commands to the end of the history
9391list without actually executing them, so that they are available for
9392subsequent recall. This is most useful in conjunction with Readline.
9393
9394 The shell allows control of the various characters used by the
9395history expansion mechanism with the 'histchars' variable, as explained
9396above (*note Bash Variables::). The shell uses the history comment
9397character to mark history timestamps when writing the history file.
9398
9399* Menu:
9400
9401* Event Designators:: How to specify which history line to use.
9402* Word Designators:: Specifying which words are of interest.
9403* Modifiers:: Modifying the results of substitution.
9404
9405\1f
9406File: bash.info, Node: Event Designators, Next: Word Designators, Up: History Interaction
9407
94089.3.1 Event Designators
9409-----------------------
9410
9411An event designator is a reference to a command line entry in the
9412history list. Unless the reference is absolute, events are relative to
9413the current position in the history list.
9414
9415'!'
9416 Start a history substitution, except when followed by a space, tab,
9417 the end of the line, '=' or '(' (when the 'extglob' shell option is
9418 enabled using the 'shopt' builtin).
9419
9420'!N'
9421 Refer to command line N.
9422
9423'!-N'
9424 Refer to the command N lines back.
9425
9426'!!'
9427 Refer to the previous command. This is a synonym for '!-1'.
9428
9429'!STRING'
9430 Refer to the most recent command preceding the current position in
9431 the history list starting with STRING.
9432
9433'!?STRING[?]'
9434 Refer to the most recent command preceding the current position in
9435 the history list containing STRING. The trailing '?' may be
9436 omitted if the STRING is followed immediately by a newline.
9437
9438'^STRING1^STRING2^'
9439 Quick Substitution. Repeat the last command, replacing STRING1
9440 with STRING2. Equivalent to '!!:s/STRING1/STRING2/'.
9441
9442'!#'
9443 The entire command line typed so far.
9444
9445\1f
9446File: bash.info, Node: Word Designators, Next: Modifiers, Prev: Event Designators, Up: History Interaction
9447
94489.3.2 Word Designators
9449----------------------
9450
9451Word designators are used to select desired words from the event. A ':'
9452separates the event specification from the word designator. It may be
9453omitted if the word designator begins with a '^', '$', '*', '-', or '%'.
9454Words are numbered from the beginning of the line, with the first word
9455being denoted by 0 (zero). Words are inserted into the current line
9456separated by single spaces.
9457
9458 For example,
9459
9460'!!'
9461 designates the preceding command. When you type this, the
9462 preceding command is repeated in toto.
9463
9464'!!:$'
9465 designates the last argument of the preceding command. This may be
9466 shortened to '!$'.
9467
9468'!fi:2'
9469 designates the second argument of the most recent command starting
9470 with the letters 'fi'.
9471
9472 Here are the word designators:
9473
9474'0 (zero)'
9475 The '0'th word. For many applications, this is the command word.
9476
9477'N'
9478 The Nth word.
9479
9480'^'
9481 The first argument; that is, word 1.
9482
9483'$'
9484 The last argument.
9485
9486'%'
9487 The word matched by the most recent '?STRING?' search.
9488
9489'X-Y'
9490 A range of words; '-Y' abbreviates '0-Y'.
9491
9492'*'
9493 All of the words, except the '0'th. This is a synonym for '1-$'.
9494 It is not an error to use '*' if there is just one word in the
9495 event; the empty string is returned in that case.
9496
9497'X*'
9498 Abbreviates 'X-$'
9499
9500'X-'
9501 Abbreviates 'X-$' like 'X*', but omits the last word.
9502
9503 If a word designator is supplied without an event specification, the
9504previous command is used as the event.
9505
9506\1f
9507File: bash.info, Node: Modifiers, Prev: Word Designators, Up: History Interaction
9508
95099.3.3 Modifiers
9510---------------
9511
9512After the optional word designator, you can add a sequence of one or
9513more of the following modifiers, each preceded by a ':'.
9514
9515'h'
9516 Remove a trailing pathname component, leaving only the head.
9517
9518't'
9519 Remove all leading pathname components, leaving the tail.
9520
9521'r'
9522 Remove a trailing suffix of the form '.SUFFIX', leaving the
9523 basename.
9524
9525'e'
9526 Remove all but the trailing suffix.
9527
9528'p'
9529 Print the new command but do not execute it.
9530
9531'q'
9532 Quote the substituted words, escaping further substitutions.
9533
9534'x'
9535 Quote the substituted words as with 'q', but break into words at
9536 spaces, tabs, and newlines.
9537
9538's/OLD/NEW/'
9539 Substitute NEW for the first occurrence of OLD in the event line.
9540 Any delimiter may be used in place of '/'. The delimiter may be
9541 quoted in OLD and NEW with a single backslash. If '&' appears in
9542 NEW, it is replaced by OLD. A single backslash will quote the '&'.
9543 The final delimiter is optional if it is the last character on the
9544 input line.
9545
9546'&'
9547 Repeat the previous substitution.
9548
9549'g'
9550'a'
9551 Cause changes to be applied over the entire event line. Used in
9552 conjunction with 's', as in 'gs/OLD/NEW/', or with '&'.
9553
9554'G'
9555 Apply the following 's' modifier once to each word in the event.
9556
9557\1f
9558File: bash.info, Node: Installing Bash, Next: Reporting Bugs, Prev: Using History Interactively, Up: Top
9559
956010 Installing Bash
9561******************
9562
9563This chapter provides basic instructions for installing Bash on the
9564various supported platforms. The distribution supports the GNU
9565operating systems, nearly every version of Unix, and several non-Unix
9566systems such as BeOS and Interix. Other independent ports exist for
9567MS-DOS, OS/2, and Windows platforms.
9568
9569* Menu:
9570
9571* Basic Installation:: Installation instructions.
9572* Compilers and Options:: How to set special options for various
9573 systems.
9574* Compiling For Multiple Architectures:: How to compile Bash for more
9575 than one kind of system from
9576 the same source tree.
9577* Installation Names:: How to set the various paths used by the installation.
9578* Specifying the System Type:: How to configure Bash for a particular system.
9579* Sharing Defaults:: How to share default configuration values among GNU
9580 programs.
9581* Operation Controls:: Options recognized by the configuration program.
9582* Optional Features:: How to enable and disable optional features when
9583 building Bash.
9584
9585\1f
9586File: bash.info, Node: Basic Installation, Next: Compilers and Options, Up: Installing Bash
9587
958810.1 Basic Installation
9589=======================
9590
9591These are installation instructions for Bash.
9592
9593 The simplest way to compile Bash is:
9594
9595 1. 'cd' to the directory containing the source code and type
9596 './configure' to configure Bash for your system. If you're using
9597 'csh' on an old version of System V, you might need to type 'sh
9598 ./configure' instead to prevent 'csh' from trying to execute
9599 'configure' itself.
9600
9601 Running 'configure' takes some time. While running, it prints
9602 messages telling which features it is checking for.
9603
9604 2. Type 'make' to compile Bash and build the 'bashbug' bug reporting
9605 script.
9606
9607 3. Optionally, type 'make tests' to run the Bash test suite.
9608
9609 4. Type 'make install' to install 'bash' and 'bashbug'. This will
9610 also install the manual pages and Info file.
9611
9612 The 'configure' shell script attempts to guess correct values for
9613various system-dependent variables used during compilation. It uses
9614those values to create a 'Makefile' in each directory of the package
9615(the top directory, the 'builtins', 'doc', and 'support' directories,
9616each directory under 'lib', and several others). It also creates a
9617'config.h' file containing system-dependent definitions. Finally, it
9618creates a shell script named 'config.status' that you can run in the
9619future to recreate the current configuration, a file 'config.cache' that
9620saves the results of its tests to speed up reconfiguring, and a file
9621'config.log' containing compiler output (useful mainly for debugging
9622'configure'). If at some point 'config.cache' contains results you
9623don't want to keep, you may remove or edit it.
9624
9625 To find out more about the options and arguments that the 'configure'
9626script understands, type
9627
d233b485 9628 bash-4.2$ ./configure --help
a0c0a00f
CR
9629
9630at the Bash prompt in your Bash source directory.
9631
d233b485
CR
9632 If you want to build Bash in a directory separate from the source
9633directory - to build for multiple architectures, for example - just use
9634the full path to the configure script. The following commands will
9635build bash in a directory under '/usr/local/build' from the source code
9636in '/usr/local/src/bash-4.4':
9637
9638 mkdir /usr/local/build/bash-4.4
9639 cd /usr/local/build/bash-4.4
9640 bash /usr/local/src/bash-4.4/configure
9641 make
9642
9643 See *note Compiling For Multiple Architectures:: for more information
9644about building in a directory separate from the source.
9645
a0c0a00f
CR
9646 If you need to do unusual things to compile Bash, please try to
9647figure out how 'configure' could check whether or not to do them, and
9648mail diffs or instructions to <bash-maintainers@gnu.org> so they can be
9649considered for the next release.
9650
9651 The file 'configure.ac' is used to create 'configure' by a program
9652called Autoconf. You only need 'configure.ac' if you want to change it
9653or regenerate 'configure' using a newer version of Autoconf. If you do
9654this, make sure you are using Autoconf version 2.50 or newer.
9655
9656 You can remove the program binaries and object files from the source
9657code directory by typing 'make clean'. To also remove the files that
9658'configure' created (so you can compile Bash for a different kind of
9659computer), type 'make distclean'.
9660
9661\1f
9662File: bash.info, Node: Compilers and Options, Next: Compiling For Multiple Architectures, Prev: Basic Installation, Up: Installing Bash
9663
966410.2 Compilers and Options
9665==========================
9666
9667Some systems require unusual options for compilation or linking that the
9668'configure' script does not know about. You can give 'configure'
9669initial values for variables by setting them in the environment. Using
9670a Bourne-compatible shell, you can do that on the command line like
9671this:
9672
9673 CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
9674
9675 On systems that have the 'env' program, you can do it like this:
9676
9677 env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
9678
9679 The configuration process uses GCC to build Bash if it is available.
9680
9681\1f
9682File: bash.info, Node: Compiling For Multiple Architectures, Next: Installation Names, Prev: Compilers and Options, Up: Installing Bash
9683
968410.3 Compiling For Multiple Architectures
9685=========================================
9686
9687You can compile Bash for more than one kind of computer at the same
9688time, by placing the object files for each architecture in their own
9689directory. To do this, you must use a version of 'make' that supports
9690the 'VPATH' variable, such as GNU 'make'. 'cd' to the directory where
9691you want the object files and executables to go and run the 'configure'
d233b485
CR
9692script from the source directory (*note Basic Installation::). You may
9693need to supply the '--srcdir=PATH' argument to tell 'configure' where
9694the source files are. 'configure' automatically checks for the source
9695code in the directory that 'configure' is in and in '..'.
a0c0a00f
CR
9696
9697 If you have to use a 'make' that does not supports the 'VPATH'
9698variable, you can compile Bash for one architecture at a time in the
9699source code directory. After you have installed Bash for one
9700architecture, use 'make distclean' before reconfiguring for another
9701architecture.
9702
9703 Alternatively, if your system supports symbolic links, you can use
9704the 'support/mkclone' script to create a build tree which has symbolic
9705links back to each file in the source directory. Here's an example that
9706creates a build directory in the current directory from a source
9707directory '/usr/gnu/src/bash-2.0':
9708
9709 bash /usr/gnu/src/bash-2.0/support/mkclone -s /usr/gnu/src/bash-2.0 .
9710
9711The 'mkclone' script requires Bash, so you must have already built Bash
9712for at least one architecture before you can create build directories
9713for other architectures.
9714
9715\1f
9716File: bash.info, Node: Installation Names, Next: Specifying the System Type, Prev: Compiling For Multiple Architectures, Up: Installing Bash
9717
971810.4 Installation Names
9719=======================
9720
9721By default, 'make install' will install into '/usr/local/bin',
9722'/usr/local/man', etc. You can specify an installation prefix other
9723than '/usr/local' by giving 'configure' the option '--prefix=PATH', or
9724by specifying a value for the 'DESTDIR' 'make' variable when running
9725'make install'.
9726
9727 You can specify separate installation prefixes for
9728architecture-specific files and architecture-independent files. If you
9729give 'configure' the option '--exec-prefix=PATH', 'make install' will
9730use PATH as the prefix for installing programs and libraries.
9731Documentation and other data files will still use the regular prefix.
9732
9733\1f
9734File: bash.info, Node: Specifying the System Type, Next: Sharing Defaults, Prev: Installation Names, Up: Installing Bash
9735
973610.5 Specifying the System Type
9737===============================
9738
9739There may be some features 'configure' can not figure out automatically,
9740but need to determine by the type of host Bash will run on. Usually
9741'configure' can figure that out, but if it prints a message saying it
9742can not guess the host type, give it the '--host=TYPE' option. 'TYPE'
9743can either be a short name for the system type, such as 'sun4', or a
9744canonical name with three fields: 'CPU-COMPANY-SYSTEM' (e.g.,
9745'i386-unknown-freebsd4.2').
9746
9747 See the file 'support/config.sub' for the possible values of each
9748field.
9749
9750\1f
9751File: bash.info, Node: Sharing Defaults, Next: Operation Controls, Prev: Specifying the System Type, Up: Installing Bash
9752
975310.6 Sharing Defaults
9754=====================
9755
9756If you want to set default values for 'configure' scripts to share, you
9757can create a site shell script called 'config.site' that gives default
9758values for variables like 'CC', 'cache_file', and 'prefix'. 'configure'
9759looks for 'PREFIX/share/config.site' if it exists, then
9760'PREFIX/etc/config.site' if it exists. Or, you can set the
9761'CONFIG_SITE' environment variable to the location of the site script.
9762A warning: the Bash 'configure' looks for a site script, but not all
9763'configure' scripts do.
9764
9765\1f
9766File: bash.info, Node: Operation Controls, Next: Optional Features, Prev: Sharing Defaults, Up: Installing Bash
9767
976810.7 Operation Controls
9769=======================
9770
9771'configure' recognizes the following options to control how it operates.
9772
9773'--cache-file=FILE'
9774 Use and save the results of the tests in FILE instead of
9775 './config.cache'. Set FILE to '/dev/null' to disable caching, for
9776 debugging 'configure'.
9777
9778'--help'
9779 Print a summary of the options to 'configure', and exit.
9780
9781'--quiet'
9782'--silent'
9783'-q'
9784 Do not print messages saying which checks are being made.
9785
9786'--srcdir=DIR'
9787 Look for the Bash source code in directory DIR. Usually
9788 'configure' can determine that directory automatically.
9789
9790'--version'
9791 Print the version of Autoconf used to generate the 'configure'
9792 script, and exit.
9793
9794 'configure' also accepts some other, not widely used, boilerplate
9795options. 'configure --help' prints the complete list.
9796
9797\1f
9798File: bash.info, Node: Optional Features, Prev: Operation Controls, Up: Installing Bash
9799
980010.8 Optional Features
9801======================
9802
9803The Bash 'configure' has a number of '--enable-FEATURE' options, where
9804FEATURE indicates an optional part of Bash. There are also several
9805'--with-PACKAGE' options, where PACKAGE is something like 'bash-malloc'
9806or 'purify'. To turn off the default use of a package, use
9807'--without-PACKAGE'. To configure Bash without a feature that is
9808enabled by default, use '--disable-FEATURE'.
9809
9810 Here is a complete list of the '--enable-' and '--with-' options that
9811the Bash 'configure' recognizes.
9812
9813'--with-afs'
9814 Define if you are using the Andrew File System from Transarc.
9815
9816'--with-bash-malloc'
9817 Use the Bash version of 'malloc' in the directory 'lib/malloc'.
9818 This is not the same 'malloc' that appears in GNU libc, but an
9819 older version originally derived from the 4.2 BSD 'malloc'. This
9820 'malloc' is very fast, but wastes some space on each allocation.
9821 This option is enabled by default. The 'NOTES' file contains a
9822 list of systems for which this should be turned off, and
9823 'configure' disables this option automatically for a number of
9824 systems.
9825
9826'--with-curses'
9827 Use the curses library instead of the termcap library. This should
9828 be supplied if your system has an inadequate or incomplete termcap
9829 database.
9830
9831'--with-gnu-malloc'
9832 A synonym for '--with-bash-malloc'.
9833
9834'--with-installed-readline[=PREFIX]'
9835 Define this to make Bash link with a locally-installed version of
9836 Readline rather than the version in 'lib/readline'. This works
9837 only with Readline 5.0 and later versions. If PREFIX is 'yes' or
9838 not supplied, 'configure' uses the values of the make variables
9839 'includedir' and 'libdir', which are subdirectories of 'prefix' by
9840 default, to find the installed version of Readline if it is not in
9841 the standard system include and library directories. If PREFIX is
9842 'no', Bash links with the version in 'lib/readline'. If PREFIX is
9843 set to any other value, 'configure' treats it as a directory
9844 pathname and looks for the installed version of Readline in
9845 subdirectories of that directory (include files in PREFIX/'include'
9846 and the library in PREFIX/'lib').
9847
9848'--with-purify'
9849 Define this to use the Purify memory allocation checker from
9850 Rational Software.
9851
9852'--enable-minimal-config'
9853 This produces a shell with minimal features, close to the
9854 historical Bourne shell.
9855
9856 There are several '--enable-' options that alter how Bash is compiled
9857and linked, rather than changing run-time features.
9858
9859'--enable-largefile'
9860 Enable support for large files
d233b485
CR
9861 (http://www.unix.org/version2/whatsnew/lfs20mar.html) if the
9862 operating system requires special compiler options to build
a0c0a00f
CR
9863 programs which can access large files. This is enabled by default,
9864 if the operating system provides large file support.
9865
9866'--enable-profiling'
9867 This builds a Bash binary that produces profiling information to be
9868 processed by 'gprof' each time it is executed.
9869
9870'--enable-static-link'
9871 This causes Bash to be linked statically, if 'gcc' is being used.
9872 This could be used to build a version to use as root's shell.
9873
9874 The 'minimal-config' option can be used to disable all of the
9875following options, but it is processed first, so individual options may
9876be enabled using 'enable-FEATURE'.
9877
9878 All of the following options except for 'disabled-builtins',
9879'direxpand-default', and 'xpg-echo-default' are enabled by default,
9880unless the operating system does not provide the necessary support.
9881
9882'--enable-alias'
9883 Allow alias expansion and include the 'alias' and 'unalias'
9884 builtins (*note Aliases::).
9885
9886'--enable-arith-for-command'
9887 Include support for the alternate form of the 'for' command that
9888 behaves like the C language 'for' statement (*note Looping
9889 Constructs::).
9890
9891'--enable-array-variables'
9892 Include support for one-dimensional array shell variables (*note
9893 Arrays::).
9894
9895'--enable-bang-history'
9896 Include support for 'csh'-like history substitution (*note History
9897 Interaction::).
9898
9899'--enable-brace-expansion'
9900 Include 'csh'-like brace expansion ( 'b{a,b}c' ==> 'bac bbc' ).
9901 See *note Brace Expansion::, for a complete description.
9902
9903'--enable-casemod-attributes'
9904 Include support for case-modifying attributes in the 'declare'
9905 builtin and assignment statements. Variables with the UPPERCASE
9906 attribute, for example, will have their values converted to
9907 uppercase upon assignment.
9908
9909'--enable-casemod-expansion'
9910 Include support for case-modifying word expansions.
9911
9912'--enable-command-timing'
9913 Include support for recognizing 'time' as a reserved word and for
9914 displaying timing statistics for the pipeline following 'time'
9915 (*note Pipelines::). This allows pipelines as well as shell
9916 builtins and functions to be timed.
9917
9918'--enable-cond-command'
9919 Include support for the '[[' conditional command. (*note
9920 Conditional Constructs::).
9921
9922'--enable-cond-regexp'
9923 Include support for matching POSIX regular expressions using the
9924 '=~' binary operator in the '[[' conditional command. (*note
9925 Conditional Constructs::).
9926
9927'--enable-coprocesses'
9928 Include support for coprocesses and the 'coproc' reserved word
9929 (*note Pipelines::).
9930
9931'--enable-debugger'
9932 Include support for the bash debugger (distributed separately).
9933
d233b485
CR
9934'--enable-dev-fd-stat-broken'
9935 If calling 'stat' on /dev/fd/N returns different results than
9936 calling 'fstat' on file descriptor N, supply this option to enable
9937 a workaround. This has implications for conditional commands that
9938 test file attributes.
9939
a0c0a00f
CR
9940'--enable-direxpand-default'
9941 Cause the 'direxpand' shell option (*note The Shopt Builtin::) to
9942 be enabled by default when the shell starts. It is normally
9943 disabled by default.
9944
9945'--enable-directory-stack'
9946 Include support for a 'csh'-like directory stack and the 'pushd',
9947 'popd', and 'dirs' builtins (*note The Directory Stack::).
9948
9949'--enable-disabled-builtins'
9950 Allow builtin commands to be invoked via 'builtin xxx' even after
9951 'xxx' has been disabled using 'enable -n xxx'. See *note Bash
9952 Builtins::, for details of the 'builtin' and 'enable' builtin
9953 commands.
9954
9955'--enable-dparen-arithmetic'
9956 Include support for the '((...))' command (*note Conditional
9957 Constructs::).
9958
9959'--enable-extended-glob'
9960 Include support for the extended pattern matching features
9961 described above under *note Pattern Matching::.
9962
9963'--enable-extended-glob-default'
9964 Set the default value of the EXTGLOB shell option described above
9965 under *note The Shopt Builtin:: to be enabled.
9966
9967'--enable-function-import'
9968 Include support for importing function definitions exported by
9969 another instance of the shell from the environment. This option is
9970 enabled by default.
9971
9972'--enable-glob-asciirange-default'
9973 Set the default value of the GLOBASCIIRANGES shell option described
9974 above under *note The Shopt Builtin:: to be enabled. This controls
9975 the behavior of character ranges when used in pattern matching
9976 bracket expressions.
9977
9978'--enable-help-builtin'
9979 Include the 'help' builtin, which displays help on shell builtins
9980 and variables (*note Bash Builtins::).
9981
9982'--enable-history'
9983 Include command history and the 'fc' and 'history' builtin commands
9984 (*note Bash History Facilities::).
9985
9986'--enable-job-control'
9987 This enables the job control features (*note Job Control::), if the
9988 operating system supports them.
9989
9990'--enable-multibyte'
9991 This enables support for multibyte characters if the operating
9992 system provides the necessary support.
9993
9994'--enable-net-redirections'
9995 This enables the special handling of filenames of the form
9996 '/dev/tcp/HOST/PORT' and '/dev/udp/HOST/PORT' when used in
9997 redirections (*note Redirections::).
9998
9999'--enable-process-substitution'
10000 This enables process substitution (*note Process Substitution::) if
10001 the operating system provides the necessary support.
10002
10003'--enable-progcomp'
10004 Enable the programmable completion facilities (*note Programmable
10005 Completion::). If Readline is not enabled, this option has no
10006 effect.
10007
10008'--enable-prompt-string-decoding'
10009 Turn on the interpretation of a number of backslash-escaped
d233b485 10010 characters in the '$PS0', '$PS1', '$PS2', and '$PS4' prompt
a0c0a00f
CR
10011 strings. See *note Controlling the Prompt::, for a complete list
10012 of prompt string escape sequences.
10013
10014'--enable-readline'
10015 Include support for command-line editing and history with the Bash
10016 version of the Readline library (*note Command Line Editing::).
10017
10018'--enable-restricted'
10019 Include support for a "restricted shell". If this is enabled,
10020 Bash, when called as 'rbash', enters a restricted mode. See *note
10021 The Restricted Shell::, for a description of restricted mode.
10022
10023'--enable-select'
10024 Include the 'select' compound command, which allows the generation
10025 of simple menus (*note Conditional Constructs::).
10026
10027'--enable-separate-helpfiles'
10028 Use external files for the documentation displayed by the 'help'
10029 builtin instead of storing the text internally.
10030
10031'--enable-single-help-strings'
10032 Store the text displayed by the 'help' builtin as a single string
10033 for each help topic. This aids in translating the text to
10034 different languages. You may need to disable this if your compiler
10035 cannot handle very long string literals.
10036
10037'--enable-strict-posix-default'
10038 Make Bash POSIX-conformant by default (*note Bash POSIX Mode::).
10039
10040'--enable-usg-echo-default'
10041 A synonym for '--enable-xpg-echo-default'.
10042
10043'--enable-xpg-echo-default'
10044 Make the 'echo' builtin expand backslash-escaped characters by
10045 default, without requiring the '-e' option. This sets the default
10046 value of the 'xpg_echo' shell option to 'on', which makes the Bash
10047 'echo' behave more like the version specified in the Single Unix
10048 Specification, version 3. *Note Bash Builtins::, for a description
10049 of the escape sequences that 'echo' recognizes.
10050
10051 The file 'config-top.h' contains C Preprocessor '#define' statements
10052for options which are not settable from 'configure'. Some of these are
10053not meant to be changed; beware of the consequences if you do. Read the
10054comments associated with each definition for more information about its
10055effect.
10056
10057\1f
10058File: bash.info, Node: Reporting Bugs, Next: Major Differences From The Bourne Shell, Prev: Installing Bash, Up: Top
10059
10060Appendix A Reporting Bugs
10061*************************
10062
10063Please report all bugs you find in Bash. But first, you should make
10064sure that it really is a bug, and that it appears in the latest version
10065of Bash. The latest version of Bash is always available for FTP from
10066<ftp://ftp.gnu.org/pub/gnu/bash/>.
10067
10068 Once you have determined that a bug actually exists, use the
10069'bashbug' command to submit a bug report. If you have a fix, you are
10070encouraged to mail that as well! Suggestions and 'philosophical' bug
10071reports may be mailed to <bug-bash@gnu.org> or posted to the Usenet
10072newsgroup 'gnu.bash.bug'.
10073
10074 All bug reports should include:
10075 * The version number of Bash.
10076 * The hardware and operating system.
10077 * The compiler used to compile Bash.
10078 * A description of the bug behaviour.
10079 * A short script or 'recipe' which exercises the bug and may be used
10080 to reproduce it.
10081
10082'bashbug' inserts the first three items automatically into the template
10083it provides for filing a bug report.
10084
10085 Please send all reports concerning this manual to <bug-bash@gnu.org>.
10086
10087\1f
10088File: bash.info, Node: Major Differences From The Bourne Shell, Next: GNU Free Documentation License, Prev: Reporting Bugs, Up: Top
10089
10090Appendix B Major Differences From The Bourne Shell
10091**************************************************
10092
10093Bash implements essentially the same grammar, parameter and variable
10094expansion, redirection, and quoting as the Bourne Shell. Bash uses the
10095POSIX standard as the specification of how these features are to be
10096implemented. There are some differences between the traditional Bourne
10097shell and Bash; this section quickly details the differences of
10098significance. A number of these differences are explained in greater
10099depth in previous sections. This section uses the version of 'sh'
10100included in SVR4.2 (the last version of the historical Bourne shell) as
10101the baseline reference.
10102
10103 * Bash is POSIX-conformant, even where the POSIX specification
10104 differs from traditional 'sh' behavior (*note Bash POSIX Mode::).
10105
10106 * Bash has multi-character invocation options (*note Invoking
10107 Bash::).
10108
10109 * Bash has command-line editing (*note Command Line Editing::) and
10110 the 'bind' builtin.
10111
10112 * Bash provides a programmable word completion mechanism (*note
10113 Programmable Completion::), and builtin commands 'complete',
10114 'compgen', and 'compopt', to manipulate it.
10115
10116 * Bash has command history (*note Bash History Facilities::) and the
10117 'history' and 'fc' builtins to manipulate it. The Bash history
10118 list maintains timestamp information and uses the value of the
10119 'HISTTIMEFORMAT' variable to display it.
10120
10121 * Bash implements 'csh'-like history expansion (*note History
10122 Interaction::).
10123
10124 * Bash has one-dimensional array variables (*note Arrays::), and the
10125 appropriate variable expansions and assignment syntax to use them.
10126 Several of the Bash builtins take options to act on arrays. Bash
10127 provides a number of built-in array variables.
10128
10129 * The '$'...'' quoting syntax, which expands ANSI-C backslash-escaped
10130 characters in the text between the single quotes, is supported
10131 (*note ANSI-C Quoting::).
10132
10133 * Bash supports the '$"..."' quoting syntax to do locale-specific
10134 translation of the characters between the double quotes. The '-D',
10135 '--dump-strings', and '--dump-po-strings' invocation options list
10136 the translatable strings found in a script (*note Locale
10137 Translation::).
10138
10139 * Bash implements the '!' keyword to negate the return value of a
10140 pipeline (*note Pipelines::). Very useful when an 'if' statement
10141 needs to act only if a test fails. The Bash '-o pipefail' option
10142 to 'set' will cause a pipeline to return a failure status if any
10143 command fails.
10144
10145 * Bash has the 'time' reserved word and command timing (*note
10146 Pipelines::). The display of the timing statistics may be
10147 controlled with the 'TIMEFORMAT' variable.
10148
10149 * Bash implements the 'for (( EXPR1 ; EXPR2 ; EXPR3 ))' arithmetic
10150 for command, similar to the C language (*note Looping
10151 Constructs::).
10152
10153 * Bash includes the 'select' compound command, which allows the
10154 generation of simple menus (*note Conditional Constructs::).
10155
10156 * Bash includes the '[[' compound command, which makes conditional
10157 testing part of the shell grammar (*note Conditional Constructs::),
10158 including optional regular expression matching.
10159
10160 * Bash provides optional case-insensitive matching for the 'case' and
10161 '[[' constructs.
10162
10163 * Bash includes brace expansion (*note Brace Expansion::) and tilde
10164 expansion (*note Tilde Expansion::).
10165
10166 * Bash implements command aliases and the 'alias' and 'unalias'
10167 builtins (*note Aliases::).
10168
10169 * Bash provides shell arithmetic, the '((' compound command (*note
10170 Conditional Constructs::), and arithmetic expansion (*note Shell
10171 Arithmetic::).
10172
10173 * Variables present in the shell's initial environment are
10174 automatically exported to child processes. The Bourne shell does
10175 not normally do this unless the variables are explicitly marked
10176 using the 'export' command.
10177
10178 * Bash supports the '+=' assignment operator, which appends to the
10179 value of the variable named on the left hand side.
10180
10181 * Bash includes the POSIX pattern removal '%', '#', '%%' and '##'
10182 expansions to remove leading or trailing substrings from variable
10183 values (*note Shell Parameter Expansion::).
10184
10185 * The expansion '${#xx}', which returns the length of '${xx}', is
10186 supported (*note Shell Parameter Expansion::).
10187
10188 * The expansion '${var:'OFFSET'[:'LENGTH']}', which expands to the
10189 substring of 'var''s value of length LENGTH, beginning at OFFSET,
10190 is present (*note Shell Parameter Expansion::).
10191
10192 * The expansion '${var/[/]'PATTERN'[/'REPLACEMENT']}', which matches
10193 PATTERN and replaces it with REPLACEMENT in the value of 'var', is
10194 available (*note Shell Parameter Expansion::).
10195
10196 * The expansion '${!PREFIX*}' expansion, which expands to the names
10197 of all shell variables whose names begin with PREFIX, is available
10198 (*note Shell Parameter Expansion::).
10199
10200 * Bash has INDIRECT variable expansion using '${!word}' (*note Shell
10201 Parameter Expansion::).
10202
10203 * Bash can expand positional parameters beyond '$9' using '${NUM}'.
10204
10205 * The POSIX '$()' form of command substitution is implemented (*note
10206 Command Substitution::), and preferred to the Bourne shell's '``'
10207 (which is also implemented for backwards compatibility).
10208
10209 * Bash has process substitution (*note Process Substitution::).
10210
10211 * Bash automatically assigns variables that provide information about
10212 the current user ('UID', 'EUID', and 'GROUPS'), the current host
10213 ('HOSTTYPE', 'OSTYPE', 'MACHTYPE', and 'HOSTNAME'), and the
10214 instance of Bash that is running ('BASH', 'BASH_VERSION', and
10215 'BASH_VERSINFO'). *Note Bash Variables::, for details.
10216
10217 * The 'IFS' variable is used to split only the results of expansion,
10218 not all words (*note Word Splitting::). This closes a longstanding
10219 shell security hole.
10220
10221 * The filename expansion bracket expression code uses '!' and '^' to
10222 negate the set of characters between the brackets. The Bourne
10223 shell uses only '!'.
10224
10225 * Bash implements the full set of POSIX filename expansion operators,
10226 including CHARACTER CLASSES, EQUIVALENCE CLASSES, and COLLATING
10227 SYMBOLS (*note Filename Expansion::).
10228
10229 * Bash implements extended pattern matching features when the
10230 'extglob' shell option is enabled (*note Pattern Matching::).
10231
10232 * It is possible to have a variable and a function with the same
10233 name; 'sh' does not separate the two name spaces.
10234
10235 * Bash functions are permitted to have local variables using the
10236 'local' builtin, and thus useful recursive functions may be written
10237 (*note Bash Builtins::).
10238
10239 * Variable assignments preceding commands affect only that command,
10240 even builtins and functions (*note Environment::). In 'sh', all
10241 variable assignments preceding commands are global unless the
10242 command is executed from the file system.
10243
10244 * Bash performs filename expansion on filenames specified as operands
10245 to input and output redirection operators (*note Redirections::).
10246
10247 * Bash contains the '<>' redirection operator, allowing a file to be
10248 opened for both reading and writing, and the '&>' redirection
10249 operator, for directing standard output and standard error to the
10250 same file (*note Redirections::).
10251
10252 * Bash includes the '<<<' redirection operator, allowing a string to
10253 be used as the standard input to a command.
10254
10255 * Bash implements the '[n]<&WORD' and '[n]>&WORD' redirection
10256 operators, which move one file descriptor to another.
10257
10258 * Bash treats a number of filenames specially when they are used in
10259 redirection operators (*note Redirections::).
10260
10261 * Bash can open network connections to arbitrary machines and
10262 services with the redirection operators (*note Redirections::).
10263
10264 * The 'noclobber' option is available to avoid overwriting existing
10265 files with output redirection (*note The Set Builtin::). The '>|'
10266 redirection operator may be used to override 'noclobber'.
10267
10268 * The Bash 'cd' and 'pwd' builtins (*note Bourne Shell Builtins::)
10269 each take '-L' and '-P' options to switch between logical and
10270 physical modes.
10271
10272 * Bash allows a function to override a builtin with the same name,
10273 and provides access to that builtin's functionality within the
10274 function via the 'builtin' and 'command' builtins (*note Bash
10275 Builtins::).
10276
10277 * The 'command' builtin allows selective disabling of functions when
10278 command lookup is performed (*note Bash Builtins::).
10279
10280 * Individual builtins may be enabled or disabled using the 'enable'
10281 builtin (*note Bash Builtins::).
10282
10283 * The Bash 'exec' builtin takes additional options that allow users
10284 to control the contents of the environment passed to the executed
10285 command, and what the zeroth argument to the command is to be
10286 (*note Bourne Shell Builtins::).
10287
10288 * Shell functions may be exported to children via the environment
10289 using 'export -f' (*note Shell Functions::).
10290
10291 * The Bash 'export', 'readonly', and 'declare' builtins can take a
10292 '-f' option to act on shell functions, a '-p' option to display
10293 variables with various attributes set in a format that can be used
10294 as shell input, a '-n' option to remove various variable
10295 attributes, and 'name=value' arguments to set variable attributes
10296 and values simultaneously.
10297
10298 * The Bash 'hash' builtin allows a name to be associated with an
10299 arbitrary filename, even when that filename cannot be found by
10300 searching the '$PATH', using 'hash -p' (*note Bourne Shell
10301 Builtins::).
10302
10303 * Bash includes a 'help' builtin for quick reference to shell
10304 facilities (*note Bash Builtins::).
10305
10306 * The 'printf' builtin is available to display formatted output
10307 (*note Bash Builtins::).
10308
10309 * The Bash 'read' builtin (*note Bash Builtins::) will read a line
10310 ending in '\' with the '-r' option, and will use the 'REPLY'
10311 variable as a default if no non-option arguments are supplied. The
10312 Bash 'read' builtin also accepts a prompt string with the '-p'
10313 option and will use Readline to obtain the line when given the '-e'
10314 option. The 'read' builtin also has additional options to control
10315 input: the '-s' option will turn off echoing of input characters as
10316 they are read, the '-t' option will allow 'read' to time out if
10317 input does not arrive within a specified number of seconds, the
10318 '-n' option will allow reading only a specified number of
10319 characters rather than a full line, and the '-d' option will read
10320 until a particular character rather than newline.
10321
10322 * The 'return' builtin may be used to abort execution of scripts
10323 executed with the '.' or 'source' builtins (*note Bourne Shell
10324 Builtins::).
10325
10326 * Bash includes the 'shopt' builtin, for finer control of shell
10327 optional capabilities (*note The Shopt Builtin::), and allows these
10328 options to be set and unset at shell invocation (*note Invoking
10329 Bash::).
10330
10331 * Bash has much more optional behavior controllable with the 'set'
10332 builtin (*note The Set Builtin::).
10333
10334 * The '-x' ('xtrace') option displays commands other than simple
10335 commands when performing an execution trace (*note The Set
10336 Builtin::).
10337
10338 * The 'test' builtin (*note Bourne Shell Builtins::) is slightly
10339 different, as it implements the POSIX algorithm, which specifies
10340 the behavior based on the number of arguments.
10341
10342 * Bash includes the 'caller' builtin, which displays the context of
10343 any active subroutine call (a shell function or a script executed
10344 with the '.' or 'source' builtins). This supports the bash
10345 debugger.
10346
10347 * The 'trap' builtin (*note Bourne Shell Builtins::) allows a 'DEBUG'
10348 pseudo-signal specification, similar to 'EXIT'. Commands specified
10349 with a 'DEBUG' trap are executed before every simple command, 'for'
10350 command, 'case' command, 'select' command, every arithmetic 'for'
10351 command, and before the first command executes in a shell function.
10352 The 'DEBUG' trap is not inherited by shell functions unless the
10353 function has been given the 'trace' attribute or the 'functrace'
10354 option has been enabled using the 'shopt' builtin. The 'extdebug'
10355 shell option has additional effects on the 'DEBUG' trap.
10356
10357 The 'trap' builtin (*note Bourne Shell Builtins::) allows an 'ERR'
10358 pseudo-signal specification, similar to 'EXIT' and 'DEBUG'.
10359 Commands specified with an 'ERR' trap are executed after a simple
10360 command fails, with a few exceptions. The 'ERR' trap is not
10361 inherited by shell functions unless the '-o errtrace' option to the
10362 'set' builtin is enabled.
10363
10364 The 'trap' builtin (*note Bourne Shell Builtins::) allows a
10365 'RETURN' pseudo-signal specification, similar to 'EXIT' and
10366 'DEBUG'. Commands specified with an 'RETURN' trap are executed
10367 before execution resumes after a shell function or a shell script
10368 executed with '.' or 'source' returns. The 'RETURN' trap is not
10369 inherited by shell functions unless the function has been given the
10370 'trace' attribute or the 'functrace' option has been enabled using
10371 the 'shopt' builtin.
10372
10373 * The Bash 'type' builtin is more extensive and gives more
10374 information about the names it finds (*note Bash Builtins::).
10375
10376 * The Bash 'umask' builtin permits a '-p' option to cause the output
10377 to be displayed in the form of a 'umask' command that may be reused
10378 as input (*note Bourne Shell Builtins::).
10379
10380 * Bash implements a 'csh'-like directory stack, and provides the
10381 'pushd', 'popd', and 'dirs' builtins to manipulate it (*note The
10382 Directory Stack::). Bash also makes the directory stack visible as
10383 the value of the 'DIRSTACK' shell variable.
10384
10385 * Bash interprets special backslash-escaped characters in the prompt
10386 strings when interactive (*note Controlling the Prompt::).
10387
10388 * The Bash restricted mode is more useful (*note The Restricted
10389 Shell::); the SVR4.2 shell restricted mode is too limited.
10390
10391 * The 'disown' builtin can remove a job from the internal shell job
10392 table (*note Job Control Builtins::) or suppress the sending of
10393 'SIGHUP' to a job when the shell exits as the result of a 'SIGHUP'.
10394
10395 * Bash includes a number of features to support a separate debugger
10396 for shell scripts.
10397
10398 * The SVR4.2 shell has two privilege-related builtins ('mldmode' and
10399 'priv') not present in Bash.
10400
10401 * Bash does not have the 'stop' or 'newgrp' builtins.
10402
10403 * Bash does not use the 'SHACCT' variable or perform shell
10404 accounting.
10405
10406 * The SVR4.2 'sh' uses a 'TIMEOUT' variable like Bash uses 'TMOUT'.
10407
10408More features unique to Bash may be found in *note Bash Features::.
10409
10410B.1 Implementation Differences From The SVR4.2 Shell
10411====================================================
10412
10413Since Bash is a completely new implementation, it does not suffer from
10414many of the limitations of the SVR4.2 shell. For instance:
10415
10416 * Bash does not fork a subshell when redirecting into or out of a
10417 shell control structure such as an 'if' or 'while' statement.
10418
10419 * Bash does not allow unbalanced quotes. The SVR4.2 shell will
10420 silently insert a needed closing quote at 'EOF' under certain
10421 circumstances. This can be the cause of some hard-to-find errors.
10422
10423 * The SVR4.2 shell uses a baroque memory management scheme based on
10424 trapping 'SIGSEGV'. If the shell is started from a process with
10425 'SIGSEGV' blocked (e.g., by using the 'system()' C library function
10426 call), it misbehaves badly.
10427
10428 * In a questionable attempt at security, the SVR4.2 shell, when
10429 invoked without the '-p' option, will alter its real and effective
10430 UID and GID if they are less than some magic threshold value,
10431 commonly 100. This can lead to unexpected results.
10432
10433 * The SVR4.2 shell does not allow users to trap 'SIGSEGV', 'SIGALRM',
10434 or 'SIGCHLD'.
10435
10436 * The SVR4.2 shell does not allow the 'IFS', 'MAILCHECK', 'PATH',
10437 'PS1', or 'PS2' variables to be unset.
10438
10439 * The SVR4.2 shell treats '^' as the undocumented equivalent of '|'.
10440
10441 * Bash allows multiple option arguments when it is invoked ('-x -v');
10442 the SVR4.2 shell allows only one option argument ('-xv'). In fact,
10443 some versions of the shell dump core if the second argument begins
10444 with a '-'.
10445
10446 * The SVR4.2 shell exits a script if any builtin fails; Bash exits a
10447 script only if one of the POSIX special builtins fails, and only
10448 for certain failures, as enumerated in the POSIX standard.
10449
10450 * The SVR4.2 shell behaves differently when invoked as 'jsh' (it
10451 turns on job control).
10452
10453\1f
10454File: bash.info, Node: GNU Free Documentation License, Next: Indexes, Prev: Major Differences From The Bourne Shell, Up: Top
10455
10456Appendix C GNU Free Documentation License
10457*****************************************
10458
10459 Version 1.3, 3 November 2008
10460
10461 Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
10462 <http://fsf.org/>
10463
10464 Everyone is permitted to copy and distribute verbatim copies
10465 of this license document, but changing it is not allowed.
10466
10467 0. PREAMBLE
10468
10469 The purpose of this License is to make a manual, textbook, or other
10470 functional and useful document "free" in the sense of freedom: to
10471 assure everyone the effective freedom to copy and redistribute it,
10472 with or without modifying it, either commercially or
10473 noncommercially. Secondarily, this License preserves for the
10474 author and publisher a way to get credit for their work, while not
10475 being considered responsible for modifications made by others.
10476
10477 This License is a kind of "copyleft", which means that derivative
10478 works of the document must themselves be free in the same sense.
10479 It complements the GNU General Public License, which is a copyleft
10480 license designed for free software.
10481
10482 We have designed this License in order to use it for manuals for
10483 free software, because free software needs free documentation: a
10484 free program should come with manuals providing the same freedoms
10485 that the software does. But this License is not limited to
10486 software manuals; it can be used for any textual work, regardless
10487 of subject matter or whether it is published as a printed book. We
10488 recommend this License principally for works whose purpose is
10489 instruction or reference.
10490
10491 1. APPLICABILITY AND DEFINITIONS
10492
10493 This License applies to any manual or other work, in any medium,
10494 that contains a notice placed by the copyright holder saying it can
10495 be distributed under the terms of this License. Such a notice
10496 grants a world-wide, royalty-free license, unlimited in duration,
10497 to use that work under the conditions stated herein. The
10498 "Document", below, refers to any such manual or work. Any member
10499 of the public is a licensee, and is addressed as "you". You accept
10500 the license if you copy, modify or distribute the work in a way
10501 requiring permission under copyright law.
10502
10503 A "Modified Version" of the Document means any work containing the
10504 Document or a portion of it, either copied verbatim, or with
10505 modifications and/or translated into another language.
10506
10507 A "Secondary Section" is a named appendix or a front-matter section
10508 of the Document that deals exclusively with the relationship of the
10509 publishers or authors of the Document to the Document's overall
10510 subject (or to related matters) and contains nothing that could
10511 fall directly within that overall subject. (Thus, if the Document
10512 is in part a textbook of mathematics, a Secondary Section may not
10513 explain any mathematics.) The relationship could be a matter of
10514 historical connection with the subject or with related matters, or
10515 of legal, commercial, philosophical, ethical or political position
10516 regarding them.
10517
10518 The "Invariant Sections" are certain Secondary Sections whose
10519 titles are designated, as being those of Invariant Sections, in the
10520 notice that says that the Document is released under this License.
10521 If a section does not fit the above definition of Secondary then it
10522 is not allowed to be designated as Invariant. The Document may
10523 contain zero Invariant Sections. If the Document does not identify
10524 any Invariant Sections then there are none.
10525
10526 The "Cover Texts" are certain short passages of text that are
10527 listed, as Front-Cover Texts or Back-Cover Texts, in the notice
10528 that says that the Document is released under this License. A
10529 Front-Cover Text may be at most 5 words, and a Back-Cover Text may
10530 be at most 25 words.
10531
10532 A "Transparent" copy of the Document means a machine-readable copy,
10533 represented in a format whose specification is available to the
10534 general public, that is suitable for revising the document
10535 straightforwardly with generic text editors or (for images composed
10536 of pixels) generic paint programs or (for drawings) some widely
10537 available drawing editor, and that is suitable for input to text
10538 formatters or for automatic translation to a variety of formats
10539 suitable for input to text formatters. A copy made in an otherwise
10540 Transparent file format whose markup, or absence of markup, has
10541 been arranged to thwart or discourage subsequent modification by
10542 readers is not Transparent. An image format is not Transparent if
10543 used for any substantial amount of text. A copy that is not
10544 "Transparent" is called "Opaque".
10545
10546 Examples of suitable formats for Transparent copies include plain
10547 ASCII without markup, Texinfo input format, LaTeX input format,
10548 SGML or XML using a publicly available DTD, and standard-conforming
10549 simple HTML, PostScript or PDF designed for human modification.
10550 Examples of transparent image formats include PNG, XCF and JPG.
10551 Opaque formats include proprietary formats that can be read and
10552 edited only by proprietary word processors, SGML or XML for which
10553 the DTD and/or processing tools are not generally available, and
10554 the machine-generated HTML, PostScript or PDF produced by some word
10555 processors for output purposes only.
10556
10557 The "Title Page" means, for a printed book, the title page itself,
10558 plus such following pages as are needed to hold, legibly, the
10559 material this License requires to appear in the title page. For
10560 works in formats which do not have any title page as such, "Title
10561 Page" means the text near the most prominent appearance of the
10562 work's title, preceding the beginning of the body of the text.
10563
10564 The "publisher" means any person or entity that distributes copies
10565 of the Document to the public.
10566
10567 A section "Entitled XYZ" means a named subunit of the Document
10568 whose title either is precisely XYZ or contains XYZ in parentheses
10569 following text that translates XYZ in another language. (Here XYZ
10570 stands for a specific section name mentioned below, such as
10571 "Acknowledgements", "Dedications", "Endorsements", or "History".)
10572 To "Preserve the Title" of such a section when you modify the
10573 Document means that it remains a section "Entitled XYZ" according
10574 to this definition.
10575
10576 The Document may include Warranty Disclaimers next to the notice
10577 which states that this License applies to the Document. These
10578 Warranty Disclaimers are considered to be included by reference in
10579 this License, but only as regards disclaiming warranties: any other
10580 implication that these Warranty Disclaimers may have is void and
10581 has no effect on the meaning of this License.
10582
10583 2. VERBATIM COPYING
10584
10585 You may copy and distribute the Document in any medium, either
10586 commercially or noncommercially, provided that this License, the
10587 copyright notices, and the license notice saying this License
10588 applies to the Document are reproduced in all copies, and that you
10589 add no other conditions whatsoever to those of this License. You
10590 may not use technical measures to obstruct or control the reading
10591 or further copying of the copies you make or distribute. However,
10592 you may accept compensation in exchange for copies. If you
10593 distribute a large enough number of copies you must also follow the
10594 conditions in section 3.
10595
10596 You may also lend copies, under the same conditions stated above,
10597 and you may publicly display copies.
10598
10599 3. COPYING IN QUANTITY
10600
10601 If you publish printed copies (or copies in media that commonly
10602 have printed covers) of the Document, numbering more than 100, and
10603 the Document's license notice requires Cover Texts, you must
10604 enclose the copies in covers that carry, clearly and legibly, all
10605 these Cover Texts: Front-Cover Texts on the front cover, and
10606 Back-Cover Texts on the back cover. Both covers must also clearly
10607 and legibly identify you as the publisher of these copies. The
10608 front cover must present the full title with all words of the title
10609 equally prominent and visible. You may add other material on the
10610 covers in addition. Copying with changes limited to the covers, as
10611 long as they preserve the title of the Document and satisfy these
10612 conditions, can be treated as verbatim copying in other respects.
10613
10614 If the required texts for either cover are too voluminous to fit
10615 legibly, you should put the first ones listed (as many as fit
10616 reasonably) on the actual cover, and continue the rest onto
10617 adjacent pages.
10618
10619 If you publish or distribute Opaque copies of the Document
10620 numbering more than 100, you must either include a machine-readable
10621 Transparent copy along with each Opaque copy, or state in or with
10622 each Opaque copy a computer-network location from which the general
10623 network-using public has access to download using public-standard
10624 network protocols a complete Transparent copy of the Document, free
10625 of added material. If you use the latter option, you must take
10626 reasonably prudent steps, when you begin distribution of Opaque
10627 copies in quantity, to ensure that this Transparent copy will
10628 remain thus accessible at the stated location until at least one
10629 year after the last time you distribute an Opaque copy (directly or
10630 through your agents or retailers) of that edition to the public.
10631
10632 It is requested, but not required, that you contact the authors of
10633 the Document well before redistributing any large number of copies,
10634 to give them a chance to provide you with an updated version of the
10635 Document.
10636
10637 4. MODIFICATIONS
10638
10639 You may copy and distribute a Modified Version of the Document
10640 under the conditions of sections 2 and 3 above, provided that you
10641 release the Modified Version under precisely this License, with the
10642 Modified Version filling the role of the Document, thus licensing
10643 distribution and modification of the Modified Version to whoever
10644 possesses a copy of it. In addition, you must do these things in
10645 the Modified Version:
10646
10647 A. Use in the Title Page (and on the covers, if any) a title
10648 distinct from that of the Document, and from those of previous
10649 versions (which should, if there were any, be listed in the
10650 History section of the Document). You may use the same title
10651 as a previous version if the original publisher of that
10652 version gives permission.
10653
10654 B. List on the Title Page, as authors, one or more persons or
10655 entities responsible for authorship of the modifications in
10656 the Modified Version, together with at least five of the
10657 principal authors of the Document (all of its principal
10658 authors, if it has fewer than five), unless they release you
10659 from this requirement.
10660
10661 C. State on the Title page the name of the publisher of the
10662 Modified Version, as the publisher.
10663
10664 D. Preserve all the copyright notices of the Document.
10665
10666 E. Add an appropriate copyright notice for your modifications
10667 adjacent to the other copyright notices.
10668
10669 F. Include, immediately after the copyright notices, a license
10670 notice giving the public permission to use the Modified
10671 Version under the terms of this License, in the form shown in
10672 the Addendum below.
10673
10674 G. Preserve in that license notice the full lists of Invariant
10675 Sections and required Cover Texts given in the Document's
10676 license notice.
10677
10678 H. Include an unaltered copy of this License.
10679
10680 I. Preserve the section Entitled "History", Preserve its Title,
10681 and add to it an item stating at least the title, year, new
10682 authors, and publisher of the Modified Version as given on the
10683 Title Page. If there is no section Entitled "History" in the
10684 Document, create one stating the title, year, authors, and
10685 publisher of the Document as given on its Title Page, then add
10686 an item describing the Modified Version as stated in the
10687 previous sentence.
10688
10689 J. Preserve the network location, if any, given in the Document
10690 for public access to a Transparent copy of the Document, and
10691 likewise the network locations given in the Document for
10692 previous versions it was based on. These may be placed in the
10693 "History" section. You may omit a network location for a work
10694 that was published at least four years before the Document
10695 itself, or if the original publisher of the version it refers
10696 to gives permission.
10697
10698 K. For any section Entitled "Acknowledgements" or "Dedications",
10699 Preserve the Title of the section, and preserve in the section
10700 all the substance and tone of each of the contributor
10701 acknowledgements and/or dedications given therein.
10702
10703 L. Preserve all the Invariant Sections of the Document, unaltered
10704 in their text and in their titles. Section numbers or the
10705 equivalent are not considered part of the section titles.
10706
10707 M. Delete any section Entitled "Endorsements". Such a section
10708 may not be included in the Modified Version.
10709
10710 N. Do not retitle any existing section to be Entitled
10711 "Endorsements" or to conflict in title with any Invariant
10712 Section.
10713
10714 O. Preserve any Warranty Disclaimers.
10715
10716 If the Modified Version includes new front-matter sections or
10717 appendices that qualify as Secondary Sections and contain no
10718 material copied from the Document, you may at your option designate
10719 some or all of these sections as invariant. To do this, add their
10720 titles to the list of Invariant Sections in the Modified Version's
10721 license notice. These titles must be distinct from any other
10722 section titles.
10723
10724 You may add a section Entitled "Endorsements", provided it contains
10725 nothing but endorsements of your Modified Version by various
10726 parties--for example, statements of peer review or that the text
10727 has been approved by an organization as the authoritative
10728 definition of a standard.
10729
10730 You may add a passage of up to five words as a Front-Cover Text,
10731 and a passage of up to 25 words as a Back-Cover Text, to the end of
10732 the list of Cover Texts in the Modified Version. Only one passage
10733 of Front-Cover Text and one of Back-Cover Text may be added by (or
10734 through arrangements made by) any one entity. If the Document
10735 already includes a cover text for the same cover, previously added
10736 by you or by arrangement made by the same entity you are acting on
10737 behalf of, you may not add another; but you may replace the old
10738 one, on explicit permission from the previous publisher that added
10739 the old one.
10740
10741 The author(s) and publisher(s) of the Document do not by this
10742 License give permission to use their names for publicity for or to
10743 assert or imply endorsement of any Modified Version.
10744
10745 5. COMBINING DOCUMENTS
10746
10747 You may combine the Document with other documents released under
10748 this License, under the terms defined in section 4 above for
10749 modified versions, provided that you include in the combination all
10750 of the Invariant Sections of all of the original documents,
10751 unmodified, and list them all as Invariant Sections of your
10752 combined work in its license notice, and that you preserve all
10753 their Warranty Disclaimers.
10754
10755 The combined work need only contain one copy of this License, and
10756 multiple identical Invariant Sections may be replaced with a single
10757 copy. If there are multiple Invariant Sections with the same name
10758 but different contents, make the title of each such section unique
10759 by adding at the end of it, in parentheses, the name of the
10760 original author or publisher of that section if known, or else a
10761 unique number. Make the same adjustment to the section titles in
10762 the list of Invariant Sections in the license notice of the
10763 combined work.
10764
10765 In the combination, you must combine any sections Entitled
10766 "History" in the various original documents, forming one section
10767 Entitled "History"; likewise combine any sections Entitled
10768 "Acknowledgements", and any sections Entitled "Dedications". You
10769 must delete all sections Entitled "Endorsements."
10770
10771 6. COLLECTIONS OF DOCUMENTS
10772
10773 You may make a collection consisting of the Document and other
10774 documents released under this License, and replace the individual
10775 copies of this License in the various documents with a single copy
10776 that is included in the collection, provided that you follow the
10777 rules of this License for verbatim copying of each of the documents
10778 in all other respects.
10779
10780 You may extract a single document from such a collection, and
10781 distribute it individually under this License, provided you insert
10782 a copy of this License into the extracted document, and follow this
10783 License in all other respects regarding verbatim copying of that
10784 document.
10785
10786 7. AGGREGATION WITH INDEPENDENT WORKS
10787
10788 A compilation of the Document or its derivatives with other
10789 separate and independent documents or works, in or on a volume of a
10790 storage or distribution medium, is called an "aggregate" if the
10791 copyright resulting from the compilation is not used to limit the
10792 legal rights of the compilation's users beyond what the individual
10793 works permit. When the Document is included in an aggregate, this
10794 License does not apply to the other works in the aggregate which
10795 are not themselves derivative works of the Document.
10796
10797 If the Cover Text requirement of section 3 is applicable to these
10798 copies of the Document, then if the Document is less than one half
10799 of the entire aggregate, the Document's Cover Texts may be placed
10800 on covers that bracket the Document within the aggregate, or the
10801 electronic equivalent of covers if the Document is in electronic
10802 form. Otherwise they must appear on printed covers that bracket
10803 the whole aggregate.
10804
10805 8. TRANSLATION
10806
10807 Translation is considered a kind of modification, so you may
10808 distribute translations of the Document under the terms of section
10809 4. Replacing Invariant Sections with translations requires special
10810 permission from their copyright holders, but you may include
10811 translations of some or all Invariant Sections in addition to the
10812 original versions of these Invariant Sections. You may include a
10813 translation of this License, and all the license notices in the
10814 Document, and any Warranty Disclaimers, provided that you also
10815 include the original English version of this License and the
10816 original versions of those notices and disclaimers. In case of a
10817 disagreement between the translation and the original version of
10818 this License or a notice or disclaimer, the original version will
10819 prevail.
10820
10821 If a section in the Document is Entitled "Acknowledgements",
10822 "Dedications", or "History", the requirement (section 4) to
10823 Preserve its Title (section 1) will typically require changing the
10824 actual title.
10825
10826 9. TERMINATION
10827
10828 You may not copy, modify, sublicense, or distribute the Document
10829 except as expressly provided under this License. Any attempt
10830 otherwise to copy, modify, sublicense, or distribute it is void,
10831 and will automatically terminate your rights under this License.
10832
10833 However, if you cease all violation of this License, then your
10834 license from a particular copyright holder is reinstated (a)
10835 provisionally, unless and until the copyright holder explicitly and
10836 finally terminates your license, and (b) permanently, if the
10837 copyright holder fails to notify you of the violation by some
10838 reasonable means prior to 60 days after the cessation.
10839
10840 Moreover, your license from a particular copyright holder is
10841 reinstated permanently if the copyright holder notifies you of the
10842 violation by some reasonable means, this is the first time you have
10843 received notice of violation of this License (for any work) from
10844 that copyright holder, and you cure the violation prior to 30 days
10845 after your receipt of the notice.
10846
10847 Termination of your rights under this section does not terminate
10848 the licenses of parties who have received copies or rights from you
10849 under this License. If your rights have been terminated and not
10850 permanently reinstated, receipt of a copy of some or all of the
10851 same material does not give you any rights to use it.
10852
10853 10. FUTURE REVISIONS OF THIS LICENSE
10854
10855 The Free Software Foundation may publish new, revised versions of
10856 the GNU Free Documentation License from time to time. Such new
10857 versions will be similar in spirit to the present version, but may
10858 differ in detail to address new problems or concerns. See
10859 <http://www.gnu.org/copyleft/>.
10860
10861 Each version of the License is given a distinguishing version
10862 number. If the Document specifies that a particular numbered
10863 version of this License "or any later version" applies to it, you
10864 have the option of following the terms and conditions either of
10865 that specified version or of any later version that has been
10866 published (not as a draft) by the Free Software Foundation. If the
10867 Document does not specify a version number of this License, you may
10868 choose any version ever published (not as a draft) by the Free
10869 Software Foundation. If the Document specifies that a proxy can
10870 decide which future versions of this License can be used, that
10871 proxy's public statement of acceptance of a version permanently
10872 authorizes you to choose that version for the Document.
10873
10874 11. RELICENSING
10875
10876 "Massive Multiauthor Collaboration Site" (or "MMC Site") means any
10877 World Wide Web server that publishes copyrightable works and also
10878 provides prominent facilities for anybody to edit those works. A
10879 public wiki that anybody can edit is an example of such a server.
10880 A "Massive Multiauthor Collaboration" (or "MMC") contained in the
10881 site means any set of copyrightable works thus published on the MMC
10882 site.
10883
10884 "CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0
10885 license published by Creative Commons Corporation, a not-for-profit
10886 corporation with a principal place of business in San Francisco,
10887 California, as well as future copyleft versions of that license
10888 published by that same organization.
10889
10890 "Incorporate" means to publish or republish a Document, in whole or
10891 in part, as part of another Document.
10892
10893 An MMC is "eligible for relicensing" if it is licensed under this
10894 License, and if all works that were first published under this
10895 License somewhere other than this MMC, and subsequently
10896 incorporated in whole or in part into the MMC, (1) had no cover
10897 texts or invariant sections, and (2) were thus incorporated prior
10898 to November 1, 2008.
10899
10900 The operator of an MMC Site may republish an MMC contained in the
10901 site under CC-BY-SA on the same site at any time before August 1,
10902 2009, provided the MMC is eligible for relicensing.
10903
10904ADDENDUM: How to use this License for your documents
10905====================================================
10906
10907To use this License in a document you have written, include a copy of
10908the License in the document and put the following copyright and license
10909notices just after the title page:
10910
10911 Copyright (C) YEAR YOUR NAME.
10912 Permission is granted to copy, distribute and/or modify this document
10913 under the terms of the GNU Free Documentation License, Version 1.3
10914 or any later version published by the Free Software Foundation;
10915 with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
10916 Texts. A copy of the license is included in the section entitled ``GNU
10917 Free Documentation License''.
10918
10919 If you have Invariant Sections, Front-Cover Texts and Back-Cover
10920Texts, replace the "with...Texts." line with this:
10921
10922 with the Invariant Sections being LIST THEIR TITLES, with
10923 the Front-Cover Texts being LIST, and with the Back-Cover Texts
10924 being LIST.
10925
10926 If you have Invariant Sections without Cover Texts, or some other
10927combination of the three, merge those two alternatives to suit the
10928situation.
10929
10930 If your document contains nontrivial examples of program code, we
10931recommend releasing these examples in parallel under your choice of free
10932software license, such as the GNU General Public License, to permit
10933their use in free software.
10934
10935\1f
10936File: bash.info, Node: Indexes, Prev: GNU Free Documentation License, Up: Top
10937
10938Appendix D Indexes
10939******************
10940
10941* Menu:
10942
10943* Builtin Index:: Index of Bash builtin commands.
10944* Reserved Word Index:: Index of Bash reserved words.
10945* Variable Index:: Quick reference helps you find the
10946 variable you want.
10947* Function Index:: Index of bindable Readline functions.
10948* Concept Index:: General index for concepts described in
10949 this manual.
10950
10951\1f
10952File: bash.info, Node: Builtin Index, Next: Reserved Word Index, Up: Indexes
10953
10954D.1 Index of Shell Builtin Commands
10955===================================
10956
10957\0\b[index\0\b]
10958* Menu:
10959
10960* .: Bourne Shell Builtins.
10961 (line 17)
10962* :: Bourne Shell Builtins.
10963 (line 11)
10964* [: Bourne Shell Builtins.
d233b485 10965 (line 269)
a0c0a00f
CR
10966* alias: Bash Builtins. (line 11)
10967* bg: Job Control Builtins.
10968 (line 7)
10969* bind: Bash Builtins. (line 21)
10970* break: Bourne Shell Builtins.
10971 (line 36)
10972* builtin: Bash Builtins. (line 102)
10973* caller: Bash Builtins. (line 111)
10974* cd: Bourne Shell Builtins.
10975 (line 44)
10976* command: Bash Builtins. (line 128)
10977* compgen: Programmable Completion Builtins.
10978 (line 12)
10979* complete: Programmable Completion Builtins.
10980 (line 30)
10981* compopt: Programmable Completion Builtins.
d233b485 10982 (line 237)
a0c0a00f
CR
10983* continue: Bourne Shell Builtins.
10984 (line 85)
10985* declare: Bash Builtins. (line 148)
10986* dirs: Directory Stack Builtins.
10987 (line 7)
10988* disown: Job Control Builtins.
d233b485
CR
10989 (line 92)
10990* echo: Bash Builtins. (line 246)
10991* enable: Bash Builtins. (line 295)
a0c0a00f
CR
10992* eval: Bourne Shell Builtins.
10993 (line 94)
10994* exec: Bourne Shell Builtins.
10995 (line 102)
10996* exit: Bourne Shell Builtins.
d233b485 10997 (line 120)
a0c0a00f 10998* export: Bourne Shell Builtins.
d233b485 10999 (line 127)
a0c0a00f
CR
11000* fc: Bash History Builtins.
11001 (line 10)
11002* fg: Job Control Builtins.
11003 (line 17)
11004* getopts: Bourne Shell Builtins.
d233b485 11005 (line 143)
a0c0a00f 11006* hash: Bourne Shell Builtins.
d233b485
CR
11007 (line 186)
11008* help: Bash Builtins. (line 324)
a0c0a00f
CR
11009* history: Bash History Builtins.
11010 (line 40)
11011* jobs: Job Control Builtins.
11012 (line 27)
11013* kill: Job Control Builtins.
11014 (line 58)
d233b485
CR
11015* let: Bash Builtins. (line 343)
11016* local: Bash Builtins. (line 351)
11017* logout: Bash Builtins. (line 365)
11018* mapfile: Bash Builtins. (line 370)
a0c0a00f
CR
11019* popd: Directory Stack Builtins.
11020 (line 35)
d233b485 11021* printf: Bash Builtins. (line 416)
a0c0a00f
CR
11022* pushd: Directory Stack Builtins.
11023 (line 53)
11024* pwd: Bourne Shell Builtins.
d233b485
CR
11025 (line 206)
11026* read: Bash Builtins. (line 460)
11027* readarray: Bash Builtins. (line 554)
a0c0a00f 11028* readonly: Bourne Shell Builtins.
d233b485 11029 (line 216)
a0c0a00f 11030* return: Bourne Shell Builtins.
d233b485 11031 (line 235)
a0c0a00f
CR
11032* set: The Set Builtin. (line 11)
11033* shift: Bourne Shell Builtins.
d233b485 11034 (line 256)
a0c0a00f 11035* shopt: The Shopt Builtin. (line 9)
d233b485 11036* source: Bash Builtins. (line 563)
a0c0a00f 11037* suspend: Job Control Builtins.
d233b485 11038 (line 104)
a0c0a00f 11039* test: Bourne Shell Builtins.
d233b485 11040 (line 269)
a0c0a00f 11041* times: Bourne Shell Builtins.
d233b485 11042 (line 348)
a0c0a00f 11043* trap: Bourne Shell Builtins.
d233b485
CR
11044 (line 354)
11045* type: Bash Builtins. (line 568)
11046* typeset: Bash Builtins. (line 600)
11047* ulimit: Bash Builtins. (line 606)
a0c0a00f 11048* umask: Bourne Shell Builtins.
d233b485
CR
11049 (line 403)
11050* unalias: Bash Builtins. (line 705)
a0c0a00f 11051* unset: Bourne Shell Builtins.
d233b485 11052 (line 421)
a0c0a00f
CR
11053* wait: Job Control Builtins.
11054 (line 76)
11055
11056\1f
11057File: bash.info, Node: Reserved Word Index, Next: Variable Index, Prev: Builtin Index, Up: Indexes
11058
11059D.2 Index of Shell Reserved Words
11060=================================
11061
11062\0\b[index\0\b]
11063* Menu:
11064
11065* !: Pipelines. (line 9)
11066* [[: Conditional Constructs.
d233b485 11067 (line 124)
a0c0a00f 11068* ]]: Conditional Constructs.
d233b485 11069 (line 124)
a0c0a00f
CR
11070* {: Command Grouping. (line 21)
11071* }: Command Grouping. (line 21)
11072* case: Conditional Constructs.
11073 (line 28)
11074* do: Looping Constructs. (line 12)
11075* done: Looping Constructs. (line 12)
11076* elif: Conditional Constructs.
11077 (line 7)
11078* else: Conditional Constructs.
11079 (line 7)
11080* esac: Conditional Constructs.
11081 (line 28)
11082* fi: Conditional Constructs.
11083 (line 7)
11084* for: Looping Constructs. (line 32)
11085* function: Shell Functions. (line 13)
11086* if: Conditional Constructs.
11087 (line 7)
11088* in: Conditional Constructs.
11089 (line 28)
11090* select: Conditional Constructs.
d233b485 11091 (line 82)
a0c0a00f
CR
11092* then: Conditional Constructs.
11093 (line 7)
11094* time: Pipelines. (line 9)
11095* until: Looping Constructs. (line 12)
11096* while: Looping Constructs. (line 22)
11097
11098\1f
11099File: bash.info, Node: Variable Index, Next: Function Index, Prev: Reserved Word Index, Up: Indexes
11100
11101D.3 Parameter and Variable Index
11102================================
11103
11104\0\b[index\0\b]
11105* Menu:
11106
d233b485
CR
11107* !: Special Parameters. (line 56)
11108* #: Special Parameters. (line 39)
11109* $: Special Parameters. (line 51)
11110* $!: Special Parameters. (line 57)
11111* $#: Special Parameters. (line 40)
11112* $$: Special Parameters. (line 52)
a0c0a00f 11113* $*: Special Parameters. (line 10)
d233b485
CR
11114* $-: Special Parameters. (line 47)
11115* $0: Special Parameters. (line 62)
11116* $?: Special Parameters. (line 43)
a0c0a00f 11117* $@: Special Parameters. (line 23)
d233b485 11118* $_: Special Parameters. (line 71)
a0c0a00f 11119* *: Special Parameters. (line 9)
d233b485
CR
11120* -: Special Parameters. (line 46)
11121* 0: Special Parameters. (line 61)
11122* ?: Special Parameters. (line 42)
a0c0a00f 11123* @: Special Parameters. (line 22)
d233b485 11124* _: Special Parameters. (line 70)
a0c0a00f
CR
11125* auto_resume: Job Control Variables.
11126 (line 6)
11127* BASH: Bash Variables. (line 13)
11128* BASHOPTS: Bash Variables. (line 16)
11129* BASHPID: Bash Variables. (line 25)
d233b485
CR
11130* BASH_ALIASES: Bash Variables. (line 32)
11131* BASH_ARGC: Bash Variables. (line 41)
11132* BASH_ARGV: Bash Variables. (line 54)
11133* BASH_ARGV0: Bash Variables. (line 66)
11134* BASH_CMDS: Bash Variables. (line 74)
11135* BASH_COMMAND: Bash Variables. (line 83)
11136* BASH_COMPAT: Bash Variables. (line 88)
11137* BASH_ENV: Bash Variables. (line 103)
11138* BASH_EXECUTION_STRING: Bash Variables. (line 109)
11139* BASH_LINENO: Bash Variables. (line 112)
11140* BASH_LOADABLES_PATH: Bash Variables. (line 120)
11141* BASH_REMATCH: Bash Variables. (line 124)
11142* BASH_SOURCE: Bash Variables. (line 132)
11143* BASH_SUBSHELL: Bash Variables. (line 139)
11144* BASH_VERSINFO: Bash Variables. (line 144)
11145* BASH_VERSION: Bash Variables. (line 167)
11146* BASH_XTRACEFD: Bash Variables. (line 170)
a0c0a00f
CR
11147* bell-style: Readline Init File Syntax.
11148 (line 38)
11149* bind-tty-special-chars: Readline Init File Syntax.
11150 (line 45)
11151* blink-matching-paren: Readline Init File Syntax.
11152 (line 50)
11153* CDPATH: Bourne Shell Variables.
11154 (line 9)
d233b485 11155* CHILD_MAX: Bash Variables. (line 181)
a0c0a00f
CR
11156* colored-completion-prefix: Readline Init File Syntax.
11157 (line 55)
11158* colored-stats: Readline Init File Syntax.
11159 (line 62)
d233b485 11160* COLUMNS: Bash Variables. (line 188)
a0c0a00f
CR
11161* comment-begin: Readline Init File Syntax.
11162 (line 68)
11163* completion-display-width: Readline Init File Syntax.
11164 (line 73)
11165* completion-ignore-case: Readline Init File Syntax.
11166 (line 80)
11167* completion-map-case: Readline Init File Syntax.
11168 (line 85)
11169* completion-prefix-display-length: Readline Init File Syntax.
11170 (line 91)
11171* completion-query-items: Readline Init File Syntax.
11172 (line 98)
d233b485
CR
11173* COMPREPLY: Bash Variables. (line 240)
11174* COMP_CWORD: Bash Variables. (line 194)
11175* COMP_KEY: Bash Variables. (line 223)
11176* COMP_LINE: Bash Variables. (line 200)
11177* COMP_POINT: Bash Variables. (line 205)
11178* COMP_TYPE: Bash Variables. (line 213)
11179* COMP_WORDBREAKS: Bash Variables. (line 227)
11180* COMP_WORDS: Bash Variables. (line 233)
a0c0a00f
CR
11181* convert-meta: Readline Init File Syntax.
11182 (line 108)
d233b485
CR
11183* COPROC: Bash Variables. (line 246)
11184* DIRSTACK: Bash Variables. (line 250)
a0c0a00f
CR
11185* disable-completion: Readline Init File Syntax.
11186 (line 116)
11187* echo-control-characters: Readline Init File Syntax.
11188 (line 121)
11189* editing-mode: Readline Init File Syntax.
11190 (line 126)
d233b485 11191* EMACS: Bash Variables. (line 260)
a0c0a00f
CR
11192* emacs-mode-string: Readline Init File Syntax.
11193 (line 132)
11194* enable-bracketed-paste: Readline Init File Syntax.
11195 (line 142)
11196* enable-keypad: Readline Init File Syntax.
11197 (line 150)
d233b485
CR
11198* ENV: Bash Variables. (line 265)
11199* EPOCHREALTIME: Bash Variables. (line 269)
11200* EPOCHSECONDS: Bash Variables. (line 277)
11201* EUID: Bash Variables. (line 284)
11202* EXECIGNORE: Bash Variables. (line 288)
a0c0a00f
CR
11203* expand-tilde: Readline Init File Syntax.
11204 (line 161)
d233b485
CR
11205* FCEDIT: Bash Variables. (line 301)
11206* FIGNORE: Bash Variables. (line 305)
11207* FUNCNAME: Bash Variables. (line 311)
11208* FUNCNEST: Bash Variables. (line 328)
11209* GLOBIGNORE: Bash Variables. (line 333)
11210* GROUPS: Bash Variables. (line 340)
11211* histchars: Bash Variables. (line 346)
11212* HISTCMD: Bash Variables. (line 361)
11213* HISTCONTROL: Bash Variables. (line 366)
11214* HISTFILE: Bash Variables. (line 382)
11215* HISTFILESIZE: Bash Variables. (line 386)
11216* HISTIGNORE: Bash Variables. (line 397)
a0c0a00f
CR
11217* history-preserve-point: Readline Init File Syntax.
11218 (line 165)
11219* history-size: Readline Init File Syntax.
11220 (line 171)
d233b485
CR
11221* HISTSIZE: Bash Variables. (line 417)
11222* HISTTIMEFORMAT: Bash Variables. (line 424)
a0c0a00f
CR
11223* HOME: Bourne Shell Variables.
11224 (line 13)
11225* horizontal-scroll-mode: Readline Init File Syntax.
11226 (line 180)
d233b485
CR
11227* HOSTFILE: Bash Variables. (line 432)
11228* HOSTNAME: Bash Variables. (line 443)
11229* HOSTTYPE: Bash Variables. (line 446)
a0c0a00f
CR
11230* IFS: Bourne Shell Variables.
11231 (line 18)
d233b485 11232* IGNOREEOF: Bash Variables. (line 449)
a0c0a00f
CR
11233* input-meta: Readline Init File Syntax.
11234 (line 187)
d233b485
CR
11235* INPUTRC: Bash Variables. (line 459)
11236* INSIDE_EMACS: Bash Variables. (line 463)
a0c0a00f
CR
11237* isearch-terminators: Readline Init File Syntax.
11238 (line 195)
11239* keymap: Readline Init File Syntax.
11240 (line 202)
d233b485
CR
11241* LANG: Bash Variables. (line 469)
11242* LC_ALL: Bash Variables. (line 473)
11243* LC_COLLATE: Bash Variables. (line 477)
11244* LC_CTYPE: Bash Variables. (line 484)
a0c0a00f 11245* LC_MESSAGES: Locale Translation. (line 11)
d233b485
CR
11246* LC_MESSAGES <1>: Bash Variables. (line 489)
11247* LC_NUMERIC: Bash Variables. (line 493)
11248* LC_TIME: Bash Variables. (line 497)
11249* LINENO: Bash Variables. (line 501)
11250* LINES: Bash Variables. (line 505)
11251* MACHTYPE: Bash Variables. (line 511)
a0c0a00f
CR
11252* MAIL: Bourne Shell Variables.
11253 (line 22)
d233b485 11254* MAILCHECK: Bash Variables. (line 515)
a0c0a00f
CR
11255* MAILPATH: Bourne Shell Variables.
11256 (line 27)
d233b485 11257* MAPFILE: Bash Variables. (line 523)
a0c0a00f
CR
11258* mark-modified-lines: Readline Init File Syntax.
11259 (line 232)
11260* mark-symlinked-directories: Readline Init File Syntax.
11261 (line 237)
11262* match-hidden-files: Readline Init File Syntax.
11263 (line 242)
11264* menu-complete-display-prefix: Readline Init File Syntax.
11265 (line 249)
11266* meta-flag: Readline Init File Syntax.
11267 (line 187)
d233b485 11268* OLDPWD: Bash Variables. (line 527)
a0c0a00f
CR
11269* OPTARG: Bourne Shell Variables.
11270 (line 34)
d233b485 11271* OPTERR: Bash Variables. (line 530)
a0c0a00f
CR
11272* OPTIND: Bourne Shell Variables.
11273 (line 38)
d233b485 11274* OSTYPE: Bash Variables. (line 534)
a0c0a00f
CR
11275* output-meta: Readline Init File Syntax.
11276 (line 254)
11277* page-completions: Readline Init File Syntax.
11278 (line 260)
11279* PATH: Bourne Shell Variables.
11280 (line 42)
d233b485
CR
11281* PIPESTATUS: Bash Variables. (line 537)
11282* POSIXLY_CORRECT: Bash Variables. (line 542)
11283* PPID: Bash Variables. (line 552)
11284* PROMPT_COMMAND: Bash Variables. (line 556)
11285* PROMPT_DIRTRIM: Bash Variables. (line 560)
11286* PS0: Bash Variables. (line 566)
a0c0a00f
CR
11287* PS1: Bourne Shell Variables.
11288 (line 48)
11289* PS2: Bourne Shell Variables.
11290 (line 53)
d233b485
CR
11291* PS3: Bash Variables. (line 571)
11292* PS4: Bash Variables. (line 576)
11293* PWD: Bash Variables. (line 584)
11294* RANDOM: Bash Variables. (line 587)
11295* READLINE_LINE: Bash Variables. (line 592)
11296* READLINE_POINT: Bash Variables. (line 596)
11297* REPLY: Bash Variables. (line 600)
a0c0a00f
CR
11298* revert-all-at-newline: Readline Init File Syntax.
11299 (line 270)
d233b485
CR
11300* SECONDS: Bash Variables. (line 603)
11301* SHELL: Bash Variables. (line 609)
11302* SHELLOPTS: Bash Variables. (line 614)
11303* SHLVL: Bash Variables. (line 623)
a0c0a00f
CR
11304* show-all-if-ambiguous: Readline Init File Syntax.
11305 (line 276)
11306* show-all-if-unmodified: Readline Init File Syntax.
11307 (line 282)
11308* show-mode-in-prompt: Readline Init File Syntax.
11309 (line 291)
11310* skip-completed-text: Readline Init File Syntax.
11311 (line 297)
11312* TEXTDOMAIN: Locale Translation. (line 11)
11313* TEXTDOMAINDIR: Locale Translation. (line 11)
d233b485
CR
11314* TIMEFORMAT: Bash Variables. (line 628)
11315* TMOUT: Bash Variables. (line 666)
11316* TMPDIR: Bash Variables. (line 678)
11317* UID: Bash Variables. (line 682)
a0c0a00f
CR
11318* vi-cmd-mode-string: Readline Init File Syntax.
11319 (line 310)
11320* vi-ins-mode-string: Readline Init File Syntax.
d233b485 11321 (line 321)
a0c0a00f 11322* visible-stats: Readline Init File Syntax.
d233b485 11323 (line 332)
a0c0a00f
CR
11324
11325\1f
11326File: bash.info, Node: Function Index, Next: Concept Index, Prev: Variable Index, Up: Indexes
11327
11328D.4 Function Index
11329==================
11330
11331\0\b[index\0\b]
11332* Menu:
11333
11334* abort (C-g): Miscellaneous Commands.
11335 (line 10)
11336* accept-line (Newline or Return): Commands For History.
11337 (line 6)
11338* alias-expand-line (): Miscellaneous Commands.
d233b485 11339 (line 125)
a0c0a00f
CR
11340* backward-char (C-b): Commands For Moving. (line 15)
11341* backward-delete-char (Rubout): Commands For Text. (line 17)
11342* backward-kill-line (C-x Rubout): Commands For Killing.
11343 (line 9)
11344* backward-kill-word (M-<DEL>): Commands For Killing.
11345 (line 24)
11346* backward-word (M-b): Commands For Moving. (line 22)
11347* beginning-of-history (M-<): Commands For History.
11348 (line 20)
11349* beginning-of-line (C-a): Commands For Moving. (line 6)
11350* bracketed-paste-begin (): Commands For Text. (line 33)
11351* call-last-kbd-macro (C-x e): Keyboard Macros. (line 13)
11352* capitalize-word (M-c): Commands For Text. (line 61)
11353* character-search (C-]): Miscellaneous Commands.
d233b485 11354 (line 42)
a0c0a00f 11355* character-search-backward (M-C-]): Miscellaneous Commands.
d233b485
CR
11356 (line 47)
11357* clear-screen (C-l): Commands For Moving. (line 48)
a0c0a00f
CR
11358* complete (<TAB>): Commands For Completion.
11359 (line 6)
11360* complete-command (M-!): Commands For Completion.
11361 (line 80)
11362* complete-filename (M-/): Commands For Completion.
11363 (line 49)
11364* complete-hostname (M-@): Commands For Completion.
11365 (line 72)
11366* complete-into-braces (M-{): Commands For Completion.
11367 (line 100)
11368* complete-username (M-~): Commands For Completion.
11369 (line 56)
11370* complete-variable (M-$): Commands For Completion.
11371 (line 64)
11372* copy-backward-word (): Commands For Killing.
11373 (line 58)
11374* copy-forward-word (): Commands For Killing.
11375 (line 63)
11376* copy-region-as-kill (): Commands For Killing.
11377 (line 54)
11378* dabbrev-expand (): Commands For Completion.
11379 (line 95)
11380* delete-char (C-d): Commands For Text. (line 12)
11381* delete-char-or-list (): Commands For Completion.
11382 (line 43)
11383* delete-horizontal-space (): Commands For Killing.
11384 (line 46)
11385* digit-argument (M-0, M-1, ... M--): Numeric Arguments. (line 6)
11386* display-shell-version (C-x C-v): Miscellaneous Commands.
d233b485
CR
11387 (line 110)
11388* do-lowercase-version (M-A, M-B, M-X, ...): Miscellaneous Commands.
a0c0a00f
CR
11389 (line 14)
11390* downcase-word (M-l): Commands For Text. (line 57)
11391* dump-functions (): Miscellaneous Commands.
d233b485 11392 (line 74)
a0c0a00f 11393* dump-macros (): Miscellaneous Commands.
d233b485 11394 (line 86)
a0c0a00f 11395* dump-variables (): Miscellaneous Commands.
d233b485 11396 (line 80)
a0c0a00f
CR
11397* dynamic-complete-history (M-<TAB>): Commands For Completion.
11398 (line 90)
d233b485
CR
11399* edit-and-execute-command (C-x C-e): Miscellaneous Commands.
11400 (line 140)
a0c0a00f
CR
11401* end-kbd-macro (C-x )): Keyboard Macros. (line 9)
11402* end-of-file (usually C-d): Commands For Text. (line 6)
11403* end-of-history (M->): Commands For History.
11404 (line 23)
11405* end-of-line (C-e): Commands For Moving. (line 9)
11406* exchange-point-and-mark (C-x C-x): Miscellaneous Commands.
d233b485 11407 (line 37)
a0c0a00f
CR
11408* forward-backward-delete-char (): Commands For Text. (line 21)
11409* forward-char (C-f): Commands For Moving. (line 12)
11410* forward-search-history (C-s): Commands For History.
11411 (line 31)
11412* forward-word (M-f): Commands For Moving. (line 18)
11413* glob-complete-word (M-g): Miscellaneous Commands.
d233b485 11414 (line 92)
a0c0a00f 11415* glob-expand-word (C-x *): Miscellaneous Commands.
d233b485 11416 (line 98)
a0c0a00f 11417* glob-list-expansions (C-x g): Miscellaneous Commands.
d233b485 11418 (line 104)
a0c0a00f 11419* history-and-alias-expand-line (): Miscellaneous Commands.
d233b485 11420 (line 128)
a0c0a00f 11421* history-expand-line (M-^): Miscellaneous Commands.
d233b485 11422 (line 118)
a0c0a00f
CR
11423* history-search-backward (): Commands For History.
11424 (line 53)
11425* history-search-forward (): Commands For History.
11426 (line 47)
d233b485 11427* history-substring-search-backward (): Commands For History.
a0c0a00f 11428 (line 65)
d233b485 11429* history-substring-search-forward (): Commands For History.
a0c0a00f
CR
11430 (line 59)
11431* insert-comment (M-#): Miscellaneous Commands.
d233b485 11432 (line 61)
a0c0a00f
CR
11433* insert-completions (M-*): Commands For Completion.
11434 (line 22)
11435* insert-last-argument (M-. or M-_): Miscellaneous Commands.
d233b485 11436 (line 131)
a0c0a00f
CR
11437* kill-line (C-k): Commands For Killing.
11438 (line 6)
11439* kill-region (): Commands For Killing.
11440 (line 50)
11441* kill-whole-line (): Commands For Killing.
11442 (line 15)
11443* kill-word (M-d): Commands For Killing.
11444 (line 19)
11445* magic-space (): Miscellaneous Commands.
d233b485 11446 (line 121)
a0c0a00f
CR
11447* menu-complete (): Commands For Completion.
11448 (line 26)
11449* menu-complete-backward (): Commands For Completion.
11450 (line 38)
11451* next-history (C-n): Commands For History.
11452 (line 17)
d233b485 11453* next-screen-line (): Commands For Moving. (line 41)
a0c0a00f
CR
11454* non-incremental-forward-search-history (M-n): Commands For History.
11455 (line 41)
11456* non-incremental-reverse-search-history (M-p): Commands For History.
11457 (line 35)
11458* operate-and-get-next (C-o): Miscellaneous Commands.
d233b485 11459 (line 134)
a0c0a00f
CR
11460* overwrite-mode (): Commands For Text. (line 65)
11461* possible-command-completions (C-x !): Commands For Completion.
11462 (line 86)
11463* possible-completions (M-?): Commands For Completion.
11464 (line 15)
11465* possible-filename-completions (C-x /): Commands For Completion.
11466 (line 52)
11467* possible-hostname-completions (C-x @): Commands For Completion.
11468 (line 76)
11469* possible-username-completions (C-x ~): Commands For Completion.
11470 (line 60)
11471* possible-variable-completions (C-x $): Commands For Completion.
11472 (line 68)
11473* prefix-meta (<ESC>): Miscellaneous Commands.
d233b485 11474 (line 19)
a0c0a00f
CR
11475* previous-history (C-p): Commands For History.
11476 (line 13)
d233b485 11477* previous-screen-line (): Commands For Moving. (line 34)
a0c0a00f
CR
11478* print-last-kbd-macro (): Keyboard Macros. (line 17)
11479* quoted-insert (C-q or C-v): Commands For Text. (line 26)
11480* re-read-init-file (C-x C-r): Miscellaneous Commands.
11481 (line 6)
d233b485 11482* redraw-current-line (): Commands For Moving. (line 52)
a0c0a00f
CR
11483* reverse-search-history (C-r): Commands For History.
11484 (line 27)
11485* revert-line (M-r): Miscellaneous Commands.
d233b485 11486 (line 26)
a0c0a00f
CR
11487* self-insert (a, b, A, 1, !, ...): Commands For Text. (line 30)
11488* set-mark (C-@): Miscellaneous Commands.
d233b485 11489 (line 33)
a0c0a00f
CR
11490* shell-backward-kill-word (): Commands For Killing.
11491 (line 33)
11492* shell-backward-word (): Commands For Moving. (line 30)
11493* shell-expand-line (M-C-e): Miscellaneous Commands.
d233b485 11494 (line 113)
a0c0a00f
CR
11495* shell-forward-word (): Commands For Moving. (line 26)
11496* shell-kill-word (): Commands For Killing.
11497 (line 28)
11498* skip-csi-sequence (): Miscellaneous Commands.
d233b485 11499 (line 52)
a0c0a00f
CR
11500* start-kbd-macro (C-x (): Keyboard Macros. (line 6)
11501* tilde-expand (M-&): Miscellaneous Commands.
d233b485 11502 (line 30)
a0c0a00f
CR
11503* transpose-chars (C-t): Commands For Text. (line 42)
11504* transpose-words (M-t): Commands For Text. (line 48)
11505* undo (C-_ or C-x C-u): Miscellaneous Commands.
d233b485 11506 (line 23)
a0c0a00f
CR
11507* universal-argument (): Numeric Arguments. (line 10)
11508* unix-filename-rubout (): Commands For Killing.
11509 (line 41)
11510* unix-line-discard (C-u): Commands For Killing.
11511 (line 12)
11512* unix-word-rubout (C-w): Commands For Killing.
11513 (line 37)
11514* upcase-word (M-u): Commands For Text. (line 53)
11515* yank (C-y): Commands For Killing.
11516 (line 68)
11517* yank-last-arg (M-. or M-_): Commands For History.
11518 (line 80)
11519* yank-nth-arg (M-C-y): Commands For History.
11520 (line 71)
11521* yank-pop (M-y): Commands For Killing.
11522 (line 71)
11523
11524\1f
11525File: bash.info, Node: Concept Index, Prev: Function Index, Up: Indexes
11526
11527D.5 Concept Index
11528=================
11529
11530\0\b[index\0\b]
11531* Menu:
11532
11533* alias expansion: Aliases. (line 6)
11534* arithmetic evaluation: Shell Arithmetic. (line 6)
11535* arithmetic expansion: Arithmetic Expansion.
11536 (line 6)
11537* arithmetic, shell: Shell Arithmetic. (line 6)
11538* arrays: Arrays. (line 6)
11539* background: Job Control Basics. (line 6)
11540* Bash configuration: Basic Installation. (line 6)
11541* Bash installation: Basic Installation. (line 6)
11542* Bourne shell: Basic Shell Features.
11543 (line 6)
11544* brace expansion: Brace Expansion. (line 6)
11545* builtin: Definitions. (line 17)
11546* command editing: Readline Bare Essentials.
11547 (line 6)
11548* command execution: Command Search and Execution.
11549 (line 6)
11550* command expansion: Simple Command Expansion.
11551 (line 6)
11552* command history: Bash History Facilities.
11553 (line 6)
11554* command search: Command Search and Execution.
11555 (line 6)
11556* command substitution: Command Substitution.
11557 (line 6)
11558* command timing: Pipelines. (line 9)
11559* commands, compound: Compound Commands. (line 6)
11560* commands, conditional: Conditional Constructs.
11561 (line 6)
11562* commands, grouping: Command Grouping. (line 6)
11563* commands, lists: Lists. (line 6)
11564* commands, looping: Looping Constructs. (line 6)
11565* commands, pipelines: Pipelines. (line 6)
11566* commands, shell: Shell Commands. (line 6)
11567* commands, simple: Simple Commands. (line 6)
11568* comments, shell: Comments. (line 6)
11569* completion builtins: Programmable Completion Builtins.
11570 (line 6)
11571* configuration: Basic Installation. (line 6)
11572* control operator: Definitions. (line 21)
11573* coprocess: Coprocesses. (line 6)
11574* directory stack: The Directory Stack. (line 6)
11575* editing command lines: Readline Bare Essentials.
11576 (line 6)
11577* environment: Environment. (line 6)
11578* evaluation, arithmetic: Shell Arithmetic. (line 6)
11579* event designators: Event Designators. (line 6)
11580* execution environment: Command Execution Environment.
11581 (line 6)
11582* exit status: Definitions. (line 26)
11583* exit status <1>: Exit Status. (line 6)
11584* expansion: Shell Expansions. (line 6)
11585* expansion, arithmetic: Arithmetic Expansion.
11586 (line 6)
11587* expansion, brace: Brace Expansion. (line 6)
11588* expansion, filename: Filename Expansion. (line 9)
11589* expansion, parameter: Shell Parameter Expansion.
11590 (line 6)
11591* expansion, pathname: Filename Expansion. (line 9)
11592* expansion, tilde: Tilde Expansion. (line 6)
11593* expressions, arithmetic: Shell Arithmetic. (line 6)
11594* expressions, conditional: Bash Conditional Expressions.
11595 (line 6)
11596* field: Definitions. (line 30)
11597* filename: Definitions. (line 35)
11598* filename expansion: Filename Expansion. (line 9)
11599* foreground: Job Control Basics. (line 6)
11600* functions, shell: Shell Functions. (line 6)
11601* history builtins: Bash History Builtins.
11602 (line 6)
11603* history events: Event Designators. (line 8)
11604* history expansion: History Interaction. (line 6)
11605* history list: Bash History Facilities.
11606 (line 6)
11607* History, how to use: A Programmable Completion Example.
d233b485 11608 (line 113)
a0c0a00f
CR
11609* identifier: Definitions. (line 51)
11610* initialization file, readline: Readline Init File. (line 6)
11611* installation: Basic Installation. (line 6)
11612* interaction, readline: Readline Interaction.
11613 (line 6)
d233b485 11614* interactive shell: Invoking Bash. (line 131)
a0c0a00f
CR
11615* interactive shell <1>: Interactive Shells. (line 6)
11616* internationalization: Locale Translation. (line 6)
11617* job: Definitions. (line 38)
11618* job control: Definitions. (line 42)
11619* job control <1>: Job Control Basics. (line 6)
11620* kill ring: Readline Killing Commands.
11621 (line 18)
11622* killing text: Readline Killing Commands.
11623 (line 6)
11624* localization: Locale Translation. (line 6)
d233b485 11625* login shell: Invoking Bash. (line 128)
a0c0a00f
CR
11626* matching, pattern: Pattern Matching. (line 6)
11627* metacharacter: Definitions. (line 46)
11628* name: Definitions. (line 51)
11629* native languages: Locale Translation. (line 6)
11630* notation, readline: Readline Bare Essentials.
11631 (line 6)
11632* operator, shell: Definitions. (line 57)
11633* parameter expansion: Shell Parameter Expansion.
11634 (line 6)
11635* parameters: Shell Parameters. (line 6)
11636* parameters, positional: Positional Parameters.
11637 (line 6)
11638* parameters, special: Special Parameters. (line 6)
11639* pathname expansion: Filename Expansion. (line 9)
11640* pattern matching: Pattern Matching. (line 6)
11641* pipeline: Pipelines. (line 6)
11642* POSIX: Definitions. (line 9)
11643* POSIX Mode: Bash POSIX Mode. (line 6)
11644* process group: Definitions. (line 62)
11645* process group ID: Definitions. (line 66)
11646* process substitution: Process Substitution.
11647 (line 6)
11648* programmable completion: Programmable Completion.
11649 (line 6)
11650* prompting: Controlling the Prompt.
11651 (line 6)
11652* quoting: Quoting. (line 6)
11653* quoting, ANSI: ANSI-C Quoting. (line 6)
11654* Readline, how to use: Job Control Variables.
11655 (line 23)
11656* redirection: Redirections. (line 6)
11657* reserved word: Definitions. (line 70)
11658* restricted shell: The Restricted Shell.
11659 (line 6)
11660* return status: Definitions. (line 75)
11661* shell arithmetic: Shell Arithmetic. (line 6)
11662* shell function: Shell Functions. (line 6)
11663* shell script: Shell Scripts. (line 6)
11664* shell variable: Shell Parameters. (line 6)
11665* shell, interactive: Interactive Shells. (line 6)
11666* signal: Definitions. (line 78)
11667* signal handling: Signals. (line 6)
11668* special builtin: Definitions. (line 82)
11669* special builtin <1>: Special Builtins. (line 6)
11670* startup files: Bash Startup Files. (line 6)
11671* suspending jobs: Job Control Basics. (line 6)
11672* tilde expansion: Tilde Expansion. (line 6)
11673* token: Definitions. (line 86)
11674* translation, native languages: Locale Translation. (line 6)
11675* variable, shell: Shell Parameters. (line 6)
11676* variables, readline: Readline Init File Syntax.
11677 (line 37)
11678* word: Definitions. (line 90)
11679* word splitting: Word Splitting. (line 6)
11680* yanking text: Readline Killing Commands.
11681 (line 6)
11682
11683
11684\1f
11685Tag Table:
d233b485
CR
11686Node: Top\7f895
11687Node: Introduction\7f2813
11688Node: What is Bash?\7f3029
11689Node: What is a shell?\7f4143
11690Node: Definitions\7f6681
11691Node: Basic Shell Features\7f9632
11692Node: Shell Syntax\7f10851
11693Node: Shell Operation\7f11877
11694Node: Quoting\7f13170
11695Node: Escape Character\7f14470
11696Node: Single Quotes\7f14955
11697Node: Double Quotes\7f15303
11698Node: ANSI-C Quoting\7f16581
11699Node: Locale Translation\7f17840
11700Node: Comments\7f18736
11701Node: Shell Commands\7f19354
11702Node: Simple Commands\7f20226
11703Node: Pipelines\7f20857
11704Node: Lists\7f23789
11705Node: Compound Commands\7f25580
11706Node: Looping Constructs\7f26592
11707Node: Conditional Constructs\7f29087
11708Node: Command Grouping\7f40170
11709Node: Coprocesses\7f41649
11710Node: GNU Parallel\7f43552
11711Node: Shell Functions\7f47610
11712Node: Shell Parameters\7f54693
11713Node: Positional Parameters\7f59106
11714Node: Special Parameters\7f60006
11715Node: Shell Expansions\7f63760
11716Node: Brace Expansion\7f65883
11717Node: Tilde Expansion\7f68607
11718Node: Shell Parameter Expansion\7f71224
11719Node: Command Substitution\7f85680
11720Node: Arithmetic Expansion\7f87035
11721Node: Process Substitution\7f87967
11722Node: Word Splitting\7f89087
11723Node: Filename Expansion\7f91031
11724Node: Pattern Matching\7f93561
11725Node: Quote Removal\7f97547
11726Node: Redirections\7f97842
11727Node: Executing Commands\7f107400
11728Node: Simple Command Expansion\7f108070
11729Node: Command Search and Execution\7f110000
11730Node: Command Execution Environment\7f112376
11731Node: Environment\7f115360
11732Node: Exit Status\7f117019
11733Node: Signals\7f118689
11734Node: Shell Scripts\7f120656
11735Node: Shell Builtin Commands\7f123171
11736Node: Bourne Shell Builtins\7f125209
11737Node: Bash Builtins\7f145959
11738Node: Modifying Shell Behavior\7f174884
11739Node: The Set Builtin\7f175229
11740Node: The Shopt Builtin\7f185642
11741Node: Special Builtins\7f203284
11742Node: Shell Variables\7f204263
11743Node: Bourne Shell Variables\7f204700
11744Node: Bash Variables\7f206804
11745Node: Bash Features\7f237264
11746Node: Invoking Bash\7f238163
11747Node: Bash Startup Files\7f244176
11748Node: Interactive Shells\7f249279
11749Node: What is an Interactive Shell?\7f249689
11750Node: Is this Shell Interactive?\7f250338
11751Node: Interactive Shell Behavior\7f251153
11752Node: Bash Conditional Expressions\7f254640
11753Node: Shell Arithmetic\7f259217
11754Node: Aliases\7f262034
11755Node: Arrays\7f264654
11756Node: The Directory Stack\7f270020
11757Node: Directory Stack Builtins\7f270804
11758Node: Controlling the Prompt\7f273772
11759Node: The Restricted Shell\7f276538
11760Node: Bash POSIX Mode\7f278363
11761Node: Job Control\7f289296
11762Node: Job Control Basics\7f289756
11763Node: Job Control Builtins\7f294724
11764Node: Job Control Variables\7f299451
11765Node: Command Line Editing\7f300607
11766Node: Introduction and Notation\7f302278
11767Node: Readline Interaction\7f303901
11768Node: Readline Bare Essentials\7f305092
11769Node: Readline Movement Commands\7f306875
11770Node: Readline Killing Commands\7f307835
11771Node: Readline Arguments\7f309753
11772Node: Searching\7f310797
11773Node: Readline Init File\7f312983
11774Node: Readline Init File Syntax\7f314130
11775Node: Conditional Init Constructs\7f334569
11776Node: Sample Init File\7f338765
11777Node: Bindable Readline Commands\7f341882
11778Node: Commands For Moving\7f343086
11779Node: Commands For History\7f344935
11780Node: Commands For Text\7f349230
11781Node: Commands For Killing\7f352618
11782Node: Numeric Arguments\7f355099
11783Node: Commands For Completion\7f356238
11784Node: Keyboard Macros\7f360429
11785Node: Miscellaneous Commands\7f361116
11786Node: Readline vi Mode\7f367069
11787Node: Programmable Completion\7f367976
11788Node: Programmable Completion Builtins\7f375756
11789Node: A Programmable Completion Example\7f386449
11790Node: Using History Interactively\7f391689
11791Node: Bash History Facilities\7f392373
11792Node: Bash History Builtins\7f395378
11793Node: History Interaction\7f399909
11794Node: Event Designators\7f403529
11795Node: Word Designators\7f404748
11796Node: Modifiers\7f406385
11797Node: Installing Bash\7f407787
11798Node: Basic Installation\7f408924
11799Node: Compilers and Options\7f412182
11800Node: Compiling For Multiple Architectures\7f412923
11801Node: Installation Names\7f414616
11802Node: Specifying the System Type\7f415434
11803Node: Sharing Defaults\7f416150
11804Node: Operation Controls\7f416823
11805Node: Optional Features\7f417781
11806Node: Reporting Bugs\7f428299
11807Node: Major Differences From The Bourne Shell\7f429493
11808Node: GNU Free Documentation License\7f446345
11809Node: Indexes\7f471522
11810Node: Builtin Index\7f471976
11811Node: Reserved Word Index\7f478803
11812Node: Variable Index\7f481251
11813Node: Function Index\7f497002
11814Node: Concept Index\7f510305
a0c0a00f
CR
11815\1f
11816End Tag Table