]> git.ipfire.org Git - thirdparty/bash.git/blame_incremental - doc/bashref.info
updated translations; remove unneeded files
[thirdparty/bash.git] / doc / bashref.info
... / ...
CommitLineData
1This is bashref.info, produced by makeinfo version 6.8 from
2bashref.texi.
3
4This text is a brief description of the features that are present in the
5Bash shell (version 5.2, 19 September 2022).
6
7 This is Edition 5.2, last updated 19 September 2022, of 'The GNU Bash
8Reference Manual', for 'Bash', Version 5.2.
9
10 Copyright (C) 1988-2022 Free Software Foundation, Inc.
11
12 Permission is granted to copy, distribute and/or modify this
13 document under the terms of the GNU Free Documentation License,
14 Version 1.3 or any later version published by the Free Software
15 Foundation; with no Invariant Sections, no Front-Cover Texts, and
16 no Back-Cover Texts. A copy of the license is included in the
17 section entitled "GNU Free Documentation License".
18INFO-DIR-SECTION Basics
19START-INFO-DIR-ENTRY
20* Bash: (bash). The GNU Bourne-Again SHell.
21END-INFO-DIR-ENTRY
22
23\1f
24File: bashref.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
30Bash shell (version 5.2, 19 September 2022). The Bash home page is
31<http://www.gnu.org/software/bash/>.
32
33 This is Edition 5.2, last updated 19 September 2022, of 'The GNU Bash
34Reference Manual', for 'Bash', Version 5.2.
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: bashref.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: bashref.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: bashref.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: bashref.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: bashref.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: bashref.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: bashref.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: bashref.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: bashref.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: bashref.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: bashref.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: bashref.info, Node: ANSI-C Quoting, Next: Locale Translation, Prev: Double Quotes, Up: Quoting
418
4193.1.2.4 ANSI-C Quoting
420......................
421
422Character sequences of the form $'STRING' are treated as a special kind
423of single quotes. The sequence expands to STRING, with
424backslash-escaped characters in STRING replaced as specified by the ANSI
425C standard. Backslash escape sequences, if present, are decoded as
426follows:
427
428'\a'
429 alert (bell)
430'\b'
431 backspace
432'\e'
433'\E'
434 an escape character (not ANSI C)
435'\f'
436 form feed
437'\n'
438 newline
439'\r'
440 carriage return
441'\t'
442 horizontal tab
443'\v'
444 vertical tab
445'\\'
446 backslash
447'\''
448 single quote
449'\"'
450 double quote
451'\?'
452 question mark
453'\NNN'
454 the eight-bit character whose value is the octal value NNN (one to
455 three octal digits)
456'\xHH'
457 the eight-bit character whose value is the hexadecimal value HH
458 (one or two hex digits)
459'\uHHHH'
460 the Unicode (ISO/IEC 10646) character whose value is the
461 hexadecimal value HHHH (one to four hex digits)
462'\UHHHHHHHH'
463 the Unicode (ISO/IEC 10646) character whose value is the
464 hexadecimal value HHHHHHHH (one to eight hex digits)
465'\cX'
466 a control-X character
467
468The expanded result is single-quoted, as if the dollar sign had not been
469present.
470
471\1f
472File: bashref.info, Node: Locale Translation, Prev: ANSI-C Quoting, Up: Quoting
473
4743.1.2.5 Locale-Specific Translation
475...................................
476
477* Menu:
478
479* Creating Internationalized Scripts:: How to use translations and different
480 languages in your scripts.
481
482Prefixing a double-quoted string with a dollar sign ('$'), such as
483$"hello, world", will cause the string to be translated according to the
484current locale. The 'gettext' infrastructure performs the lookup and
485translation, using the 'LC_MESSAGES', 'TEXTDOMAINDIR', and 'TEXTDOMAIN'
486shell variables, as explained below. See the gettext documentation for
487additional details not covered here. If the current locale is 'C' or
488'POSIX', if there are no translations available, of if the string is not
489translated, the dollar sign is ignored. Since this is a form of double
490quoting, the string remains double-quoted by default, whether or not it
491is translated and replaced. If the 'noexpand_translation' option is
492enabled using the 'shopt' builtin (*note The Shopt Builtin::),
493translated strings are single-quoted instead of double-quoted.
494
495 The rest of this section is a brief overview of how you use gettext
496to create translations for strings in a shell script named SCRIPTNAME.
497There are more details in the gettext documentation.
498
499\1f
500File: bashref.info, Node: Creating Internationalized Scripts, Up: Locale Translation
501
502Once you've marked the strings in your script that you want to translate
503using $"...", you create a gettext "template" file using the command
504
505 bash --dump-po-strings SCRIPTNAME > DOMAIN.pot
506
507The DOMAIN is your "message domain". It's just an arbitrary string
508that's used to identify the files gettext needs, like a package or
509script name. It needs to be unique among all the message domains on
510systems where you install the translations, so gettext knows which
511translations correspond to your script. You'll use the template file to
512create translations for each target language. The template file
513conventionally has the suffix '.pot'.
514
515 You copy this template file to a separate file for each target
516language you want to support (called "PO" files, which use the suffix
517'.po'). PO files use various naming conventions, but when you are
518working to translate a template file into a particular language, you
519first copy the template file to a file whose name is the language you
520want to target, with the '.po' suffix. For instance, the Spanish
521translations of your strings would be in a file named 'es.po', and to
522get started using a message domain named "example," you would run
523
524 cp example.pot es.po
525
526Ultimately, PO files are often named DOMAIN.po and installed in
527directories that contain multiple translation files for a particular
528language.
529
530 Whichever naming convention you choose, you will need to translate
531the strings in the PO files into the appropriate languages. This has to
532be done manually.
533
534 When you have the translations and PO files complete, you'll use the
535gettext tools to produce what are called "MO" files, which are compiled
536versions of the PO files the gettext tools use to look up translations
537efficiently. MO files are also called "message catalog" files. You use
538the 'msgfmt' program to do this. For instance, if you had a file with
539Spanish translations, you could run
540
541 msgfmt -o es.mo es.po
542
543to produce the corresponding MO file.
544
545 Once you have the MO files, you decide where to install them and use
546the 'TEXTDOMAINDIR' shell variable to tell the gettext tools where they
547are. Make sure to use the same message domain to name the MO files as
548you did for the PO files when you install them.
549
550 Your users will use the 'LANG' or 'LC_MESSAGES' shell variables to
551select the desired language.
552
553 You set the 'TEXTDOMAIN' variable to the script's message domain. As
554above, you use the message domain to name your translation files.
555
556 You, or possibly your users, set the 'TEXTDOMAINDIR' variable to the
557name of a directory where the message catalog files are stored. If you
558install the message files into the system's standard message catalog
559directory, you don't need to worry about this variable.
560
561 The directory where the message catalog files are stored varies
562between systems. Some use the message catalog selected by the
563'LC_MESSAGES' shell variable. Others create the name of the message
564catalog from the value of the 'TEXTDOMAIN' shell variable, possibly
565adding the '.mo' suffix. If you use the 'TEXTDOMAIN' variable, you may
566need to set the 'TEXTDOMAINDIR' variable to the location of the message
567catalog files, as above. It's common to use both variables in this
568fashion: '$TEXTDOMAINDIR'/'$LC_MESSAGES'/LC_MESSAGES/'$TEXTDOMAIN'.mo.
569
570 If you used that last convention, and you wanted to store the message
571catalog files with Spanish (es) and Esperanto (eo) translations into a
572local directory you use for custom translation files, you could run
573
574 TEXTDOMAIN=example
575 TEXTDOMAINDIR=/usr/local/share/locale
576
577 cp es.mo ${TEXTDOMAINDIR}/es/LC_MESSAGES/${TEXTDOMAIN}.mo
578 cp eo.mo ${TEXTDOMAINDIR}/eo/LC_MESSAGES/${TEXTDOMAIN}.mo
579
580 When all of this is done, and the message catalog files containing
581the compiled translations are installed in the correct location, your
582users will be able to see translated strings in any of the supported
583languages by setting the 'LANG' or 'LC_MESSAGES' environment variables
584before running your script.
585
586\1f
587File: bashref.info, Node: Comments, Prev: Quoting, Up: Shell Syntax
588
5893.1.3 Comments
590--------------
591
592In a non-interactive shell, or an interactive shell in which the
593'interactive_comments' option to the 'shopt' builtin is enabled (*note
594The Shopt Builtin::), a word beginning with '#' causes that word and all
595remaining characters on that line to be ignored. An interactive shell
596without the 'interactive_comments' option enabled does not allow
597comments. The 'interactive_comments' option is on by default in
598interactive shells. *Note Interactive Shells::, for a description of
599what makes a shell interactive.
600
601\1f
602File: bashref.info, Node: Shell Commands, Next: Shell Functions, Prev: Shell Syntax, Up: Basic Shell Features
603
6043.2 Shell Commands
605==================
606
607A simple shell command such as 'echo a b c' consists of the command
608itself followed by arguments, separated by spaces.
609
610 More complex shell commands are composed of simple commands arranged
611together in a variety of ways: in a pipeline in which the output of one
612command becomes the input of a second, in a loop or conditional
613construct, or in some other grouping.
614
615* Menu:
616
617* Reserved Words:: Words that have special meaning to the shell.
618* Simple Commands:: The most common type of command.
619* Pipelines:: Connecting the input and output of several
620 commands.
621* Lists:: How to execute commands sequentially.
622* Compound Commands:: Shell commands for control flow.
623* Coprocesses:: Two-way communication between commands.
624* GNU Parallel:: Running commands in parallel.
625
626\1f
627File: bashref.info, Node: Reserved Words, Next: Simple Commands, Up: Shell Commands
628
6293.2.1 Reserved Words
630--------------------
631
632Reserved words are words that have special meaning to the shell. They
633are used to begin and end the shell's compound commands.
634
635 The following words are recognized as reserved when unquoted and the
636first word of a command (see below for exceptions):
637
638'if' 'then' 'elif' 'else' 'fi' 'time'
639'for' 'in' 'until' 'while' 'do' 'done'
640'case' 'esac' 'coproc''select''function'
641'{' '}' '[[' ']]' '!'
642
643'in' is recognized as a reserved word if it is the third word of a
644'case' or 'select' command. 'in' and 'do' are recognized as reserved
645words if they are the third word in a 'for' command.
646
647\1f
648File: bashref.info, Node: Simple Commands, Next: Pipelines, Prev: Reserved Words, Up: Shell Commands
649
6503.2.2 Simple Commands
651---------------------
652
653A simple command is the kind of command encountered most often. It's
654just a sequence of words separated by 'blank's, terminated by one of the
655shell's control operators (*note Definitions::). The first word
656generally specifies a command to be executed, with the rest of the words
657being that command's arguments.
658
659 The return status (*note Exit Status::) of a simple command is its
660exit status as provided by the POSIX 1003.1 'waitpid' function, or 128+N
661if the command was terminated by signal N.
662
663\1f
664File: bashref.info, Node: Pipelines, Next: Lists, Prev: Simple Commands, Up: Shell Commands
665
6663.2.3 Pipelines
667---------------
668
669A 'pipeline' is a sequence of one or more commands separated by one of
670the control operators '|' or '|&'.
671
672 The format for a pipeline is
673 [time [-p]] [!] COMMAND1 [ | or |& COMMAND2 ] ...
674
675The output of each command in the pipeline is connected via a pipe to
676the input of the next command. That is, each command reads the previous
677command's output. This connection is performed before any redirections
678specified by COMMAND1.
679
680 If '|&' is used, COMMAND1's standard error, in addition to its
681standard output, is connected to COMMAND2's standard input through the
682pipe; it is shorthand for '2>&1 |'. This implicit redirection of the
683standard error to the standard output is performed after any
684redirections specified by COMMAND1.
685
686 The reserved word 'time' causes timing statistics to be printed for
687the pipeline once it finishes. The statistics currently consist of
688elapsed (wall-clock) time and user and system time consumed by the
689command's execution. The '-p' option changes the output format to that
690specified by POSIX. When the shell is in POSIX mode (*note Bash POSIX
691Mode::), it does not recognize 'time' as a reserved word if the next
692token begins with a '-'. The 'TIMEFORMAT' variable may be set to a
693format string that specifies how the timing information should be
694displayed. *Note Bash Variables::, for a description of the available
695formats. The use of 'time' as a reserved word permits the timing of
696shell builtins, shell functions, and pipelines. An external 'time'
697command cannot time these easily.
698
699 When the shell is in POSIX mode (*note Bash POSIX Mode::), 'time' may
700be followed by a newline. In this case, the shell displays the total
701user and system time consumed by the shell and its children. The
702'TIMEFORMAT' variable may be used to specify the format of the time
703information.
704
705 If the pipeline is not executed asynchronously (*note Lists::), the
706shell waits for all commands in the pipeline to complete.
707
708 Each command in a multi-command pipeline, where pipes are created, is
709executed in its own "subshell", which is a separate process (*note
710Command Execution Environment::). If the 'lastpipe' option is enabled
711using the 'shopt' builtin (*note The Shopt Builtin::), the last element
712of a pipeline may be run by the shell process when job control is not
713active.
714
715 The exit status of a pipeline is the exit status of the last command
716in the pipeline, unless the 'pipefail' option is enabled (*note The Set
717Builtin::). If 'pipefail' is enabled, the pipeline's return status is
718the value of the last (rightmost) command to exit with a non-zero
719status, or zero if all commands exit successfully. If the reserved word
720'!' precedes the pipeline, the exit status is the logical negation of
721the exit status as described above. The shell waits for all commands in
722the pipeline to terminate before returning a value.
723
724\1f
725File: bashref.info, Node: Lists, Next: Compound Commands, Prev: Pipelines, Up: Shell Commands
726
7273.2.4 Lists of Commands
728-----------------------
729
730A 'list' is a sequence of one or more pipelines separated by one of the
731operators ';', '&', '&&', or '||', and optionally terminated by one of
732';', '&', or a 'newline'.
733
734 Of these list operators, '&&' and '||' have equal precedence,
735followed by ';' and '&', which have equal precedence.
736
737 A sequence of one or more newlines may appear in a 'list' to delimit
738commands, equivalent to a semicolon.
739
740 If a command is terminated by the control operator '&', the shell
741executes the command asynchronously in a subshell. This is known as
742executing the command in the "background", and these are referred to as
743"asynchronous" commands. The shell does not wait for the command to
744finish, and the return status is 0 (true). When job control is not
745active (*note Job Control::), the standard input for asynchronous
746commands, in the absence of any explicit redirections, is redirected
747from '/dev/null'.
748
749 Commands separated by a ';' are executed sequentially; the shell
750waits for each command to terminate in turn. The return status is the
751exit status of the last command executed.
752
753 AND and OR lists are sequences of one or more pipelines separated by
754the control operators '&&' and '||', respectively. AND and OR lists are
755executed with left associativity.
756
757 An AND list has the form
758 COMMAND1 && COMMAND2
759
760COMMAND2 is executed if, and only if, COMMAND1 returns an exit status of
761zero (success).
762
763 An OR list has the form
764 COMMAND1 || COMMAND2
765
766COMMAND2 is executed if, and only if, COMMAND1 returns a non-zero exit
767status.
768
769 The return status of AND and OR lists is the exit status of the last
770command executed in the list.
771
772\1f
773File: bashref.info, Node: Compound Commands, Next: Coprocesses, Prev: Lists, Up: Shell Commands
774
7753.2.5 Compound Commands
776-----------------------
777
778* Menu:
779
780* Looping Constructs:: Shell commands for iterative action.
781* Conditional Constructs:: Shell commands for conditional execution.
782* Command Grouping:: Ways to group commands.
783
784Compound commands are the shell programming language constructs. Each
785construct begins with a reserved word or control operator and is
786terminated by a corresponding reserved word or operator. Any
787redirections (*note Redirections::) associated with a compound command
788apply to all commands within that compound command unless explicitly
789overridden.
790
791 In most cases a list of commands in a compound command's description
792may be separated from the rest of the command by one or more newlines,
793and may be followed by a newline in place of a semicolon.
794
795 Bash provides looping constructs, conditional commands, and
796mechanisms to group commands and execute them as a unit.
797
798\1f
799File: bashref.info, Node: Looping Constructs, Next: Conditional Constructs, Up: Compound Commands
800
8013.2.5.1 Looping Constructs
802..........................
803
804Bash supports the following looping constructs.
805
806 Note that wherever a ';' appears in the description of a command's
807syntax, it may be replaced with one or more newlines.
808
809'until'
810 The syntax of the 'until' command is:
811
812 until TEST-COMMANDS; do CONSEQUENT-COMMANDS; done
813
814 Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit
815 status which is not zero. The return status is the exit status of
816 the last command executed in CONSEQUENT-COMMANDS, or zero if none
817 was executed.
818
819'while'
820 The syntax of the 'while' command is:
821
822 while TEST-COMMANDS; do CONSEQUENT-COMMANDS; done
823
824 Execute CONSEQUENT-COMMANDS as long as TEST-COMMANDS has an exit
825 status of zero. The return status is the exit status of the last
826 command executed in CONSEQUENT-COMMANDS, or zero if none was
827 executed.
828
829'for'
830 The syntax of the 'for' command is:
831
832 for NAME [ [in [WORDS ...] ] ; ] do COMMANDS; done
833
834 Expand WORDS (*note Shell Expansions::), and execute COMMANDS once
835 for each member in the resultant list, with NAME bound to the
836 current member. If 'in WORDS' is not present, the 'for' command
837 executes the COMMANDS once for each positional parameter that is
838 set, as if 'in "$@"' had been specified (*note Special
839 Parameters::).
840
841 The return status is the exit status of the last command that
842 executes. If there are no items in the expansion of WORDS, no
843 commands are executed, and the return status is zero.
844
845 An alternate form of the 'for' command is also supported:
846
847 for (( EXPR1 ; EXPR2 ; EXPR3 )) ; do COMMANDS ; done
848
849 First, the arithmetic expression EXPR1 is evaluated according to
850 the rules described below (*note Shell Arithmetic::). The
851 arithmetic expression EXPR2 is then evaluated repeatedly until it
852 evaluates to zero. Each time EXPR2 evaluates to a non-zero value,
853 COMMANDS are executed and the arithmetic expression EXPR3 is
854 evaluated. If any expression is omitted, it behaves as if it
855 evaluates to 1. The return value is the exit status of the last
856 command in COMMANDS that is executed, or false if any of the
857 expressions is invalid.
858
859 The 'break' and 'continue' builtins (*note Bourne Shell Builtins::)
860may be used to control loop execution.
861
862\1f
863File: bashref.info, Node: Conditional Constructs, Next: Command Grouping, Prev: Looping Constructs, Up: Compound Commands
864
8653.2.5.2 Conditional Constructs
866..............................
867
868'if'
869 The syntax of the 'if' command is:
870
871 if TEST-COMMANDS; then
872 CONSEQUENT-COMMANDS;
873 [elif MORE-TEST-COMMANDS; then
874 MORE-CONSEQUENTS;]
875 [else ALTERNATE-CONSEQUENTS;]
876 fi
877
878 The TEST-COMMANDS list is executed, and if its return status is
879 zero, the CONSEQUENT-COMMANDS list is executed. If TEST-COMMANDS
880 returns a non-zero status, each 'elif' list is executed in turn,
881 and if its exit status is zero, the corresponding MORE-CONSEQUENTS
882 is executed and the command completes. If 'else
883 ALTERNATE-CONSEQUENTS' is present, and the final command in the
884 final 'if' or 'elif' clause has a non-zero exit status, then
885 ALTERNATE-CONSEQUENTS is executed. The return status is the exit
886 status of the last command executed, or zero if no condition tested
887 true.
888
889'case'
890 The syntax of the 'case' command is:
891
892 case WORD in
893 [ [(] PATTERN [| PATTERN]...) COMMAND-LIST ;;]...
894 esac
895
896 'case' will selectively execute the COMMAND-LIST corresponding to
897 the first PATTERN that matches WORD. The match is performed
898 according to the rules described below in *note Pattern Matching::.
899 If the 'nocasematch' shell option (see the description of 'shopt'
900 in *note The Shopt Builtin::) is enabled, the match is performed
901 without regard to the case of alphabetic characters. The '|' is
902 used to separate multiple patterns, and the ')' operator terminates
903 a pattern list. A list of patterns and an associated command-list
904 is known as a CLAUSE.
905
906 Each clause must be terminated with ';;', ';&', or ';;&'. The WORD
907 undergoes tilde expansion, parameter expansion, command
908 substitution, arithmetic expansion, and quote removal (*note Shell
909 Parameter Expansion::) before matching is attempted. Each PATTERN
910 undergoes tilde expansion, parameter expansion, command
911 substitution, arithmetic expansion, process substitution, and quote
912 removal.
913
914 There may be an arbitrary number of 'case' clauses, each terminated
915 by a ';;', ';&', or ';;&'. The first pattern that matches
916 determines the command-list that is executed. It's a common idiom
917 to use '*' as the final pattern to define the default case, since
918 that pattern will always match.
919
920 Here is an example using 'case' in a script that could be used to
921 describe one interesting feature of an animal:
922
923 echo -n "Enter the name of an animal: "
924 read ANIMAL
925 echo -n "The $ANIMAL has "
926 case $ANIMAL in
927 horse | dog | cat) echo -n "four";;
928 man | kangaroo ) echo -n "two";;
929 *) echo -n "an unknown number of";;
930 esac
931 echo " legs."
932
933
934 If the ';;' operator is used, no subsequent matches are attempted
935 after the first pattern match. Using ';&' in place of ';;' causes
936 execution to continue with the COMMAND-LIST associated with the
937 next clause, if any. Using ';;&' in place of ';;' causes the shell
938 to test the patterns in the next clause, if any, and execute any
939 associated COMMAND-LIST on a successful match, continuing the case
940 statement execution as if the pattern list had not matched.
941
942 The return status is zero if no PATTERN is matched. Otherwise, the
943 return status is the exit status of the COMMAND-LIST executed.
944
945'select'
946
947 The 'select' construct allows the easy generation of menus. It has
948 almost the same syntax as the 'for' command:
949
950 select NAME [in WORDS ...]; do COMMANDS; done
951
952 The list of words following 'in' is expanded, generating a list of
953 items, and the set of expanded words is printed on the standard
954 error output stream, each preceded by a number. If the 'in WORDS'
955 is omitted, the positional parameters are printed, as if 'in "$@"'
956 had been specified. 'select' then displays the 'PS3' prompt and
957 reads a line from the standard input. If the line consists of a
958 number corresponding to one of the displayed words, then the value
959 of NAME is set to that word. If the line is empty, the words and
960 prompt are displayed again. If 'EOF' is read, the 'select' command
961 completes and returns 1. Any other value read causes NAME to be
962 set to null. The line read is saved in the variable 'REPLY'.
963
964 The COMMANDS are executed after each selection until a 'break'
965 command is executed, at which point the 'select' command completes.
966
967 Here is an example that allows the user to pick a filename from the
968 current directory, and displays the name and index of the file
969 selected.
970
971 select fname in *;
972 do
973 echo you picked $fname \($REPLY\)
974 break;
975 done
976
977'((...))'
978 (( EXPRESSION ))
979
980 The arithmetic EXPRESSION is evaluated according to the rules
981 described below (*note Shell Arithmetic::). The EXPRESSION
982 undergoes the same expansions as if it were within double quotes,
983 but double quote characters in EXPRESSION are not treated specially
984 are removed. If the value of the expression is non-zero, the
985 return status is 0; otherwise the return status is 1.
986
987'[[...]]'
988 [[ EXPRESSION ]]
989
990 Return a status of 0 or 1 depending on the evaluation of the
991 conditional expression EXPRESSION. Expressions are composed of the
992 primaries described below in *note Bash Conditional Expressions::.
993 The words between the '[[' and ']]' do not undergo word splitting
994 and filename expansion. The shell performs tilde expansion,
995 parameter and variable expansion, arithmetic expansion, command
996 substitution, process substitution, and quote removal on those
997 words (the expansions that would occur if the words were enclosed
998 in double quotes). Conditional operators such as '-f' must be
999 unquoted to be recognized as primaries.
1000
1001 When used with '[[', the '<' and '>' operators sort
1002 lexicographically using the current locale.
1003
1004 When the '==' and '!=' operators are used, the string to the right
1005 of the operator is considered a pattern and matched according to
1006 the rules described below in *note Pattern Matching::, as if the
1007 'extglob' shell option were enabled. The '=' operator is identical
1008 to '=='. If the 'nocasematch' shell option (see the description of
1009 'shopt' in *note The Shopt Builtin::) is enabled, the match is
1010 performed without regard to the case of alphabetic characters. The
1011 return value is 0 if the string matches ('==') or does not match
1012 ('!=') the pattern, and 1 otherwise.
1013
1014 If you quote any part of the pattern, using any of the shell's
1015 quoting mechanisms, the quoted portion is matched literally. This
1016 means every character in the quoted portion matches itself, instead
1017 of having any special pattern matching meaning.
1018
1019 An additional binary operator, '=~', is available, with the same
1020 precedence as '==' and '!='. When you use '=~', the string to the
1021 right of the operator is considered a POSIX extended regular
1022 expression pattern and matched accordingly (using the POSIX
1023 'regcomp' and 'regexec' interfaces usually described in regex(3)).
1024 The return value is 0 if the string matches the pattern, and 1 if
1025 it does not. If the regular expression is syntactically incorrect,
1026 the conditional expression returns 2. If the 'nocasematch' shell
1027 option (see the description of 'shopt' in *note The Shopt
1028 Builtin::) is enabled, the match is performed without regard to the
1029 case of alphabetic characters.
1030
1031 You can quote any part of the pattern to force the quoted portion
1032 to be matched literally instead of as a regular expression (see
1033 above). If the pattern is stored in a shell variable, quoting the
1034 variable expansion forces the entire pattern to be matched
1035 literally.
1036
1037 The pattern will match if it matches any part of the string. If
1038 you want to force the pattern to match the entire string, anchor
1039 the pattern using the '^' and '$' regular expression operators.
1040
1041 For example, the following will match a line (stored in the shell
1042 variable 'line') if there is a sequence of characters anywhere in
1043 the value consisting of any number, including zero, of characters
1044 in the 'space' character class, immediately followed by zero or one
1045 instances of 'a', then a 'b':
1046
1047 [[ $line =~ [[:space:]]*(a)?b ]]
1048
1049 That means values for 'line' like 'aab', ' aaaaaab', 'xaby', and '
1050 ab' will all match, as will a line containing a 'b' anywhere in its
1051 value.
1052
1053 If you want to match a character that's special to the regular
1054 expression grammar ('^$|[]()\.*+?'), it has to be quoted to remove
1055 its special meaning. This means that in the pattern 'xxx.txt', the
1056 '.' matches any character in the string (its usual regular
1057 expression meaning), but in the pattern '"xxx.txt"', it can only
1058 match a literal '.'.
1059
1060 Likewise, if you want to include a character in your pattern that
1061 has a special meaning to the regular expression grammar, you must
1062 make sure it's not quoted. If you want to anchor a pattern at the
1063 beginning or end of the string, for instance, you cannot quote the
1064 '^' or '$' characters using any form of shell quoting.
1065
1066 If you want to match 'initial string' at the start of a line, the
1067 following will work:
1068 [[ $line =~ ^"initial string" ]]
1069 but this will not:
1070 [[ $line =~ "^initial string" ]]
1071 because in the second example the '^' is quoted and doesn't have
1072 its usual special meaning.
1073
1074 It is sometimes difficult to specify a regular expression properly
1075 without using quotes, or to keep track of the quoting used by
1076 regular expressions while paying attention to shell quoting and the
1077 shell's quote removal. Storing the regular expression in a shell
1078 variable is often a useful way to avoid problems with quoting
1079 characters that are special to the shell. For example, the
1080 following is equivalent to the pattern used above:
1081
1082 pattern='[[:space:]]*(a)?b'
1083 [[ $line =~ $pattern ]]
1084
1085 Shell programmers should take special care with backslashes, since
1086 backslashes are used by both the shell and regular expressions to
1087 remove the special meaning from the following character. This
1088 means that after the shell's word expansions complete (*note Shell
1089 Expansions::), any backslashes remaining in parts of the pattern
1090 that were originally not quoted can remove the special meaning of
1091 pattern characters. If any part of the pattern is quoted, the
1092 shell does its best to ensure that the regular expression treats
1093 those remaining backslashes as literal, if they appeared in a
1094 quoted portion.
1095
1096 The following two sets of commands are _not_ equivalent:
1097
1098 pattern='\.'
1099
1100 [[ . =~ $pattern ]]
1101 [[ . =~ \. ]]
1102
1103 [[ . =~ "$pattern" ]]
1104 [[ . =~ '\.' ]]
1105
1106 The first two matches will succeed, but the second two will not,
1107 because in the second two the backslash will be part of the pattern
1108 to be matched. In the first two examples, the pattern passed to
1109 the regular expression parser is '\.'. The backslash removes the
1110 special meaning from '.', so the literal '.' matches. In the
1111 second two examples, the pattern passed to the regular expression
1112 parser has the backslash quoted (e.g., '\\\.'), which will not
1113 match the string, since it does not contain a backslash. If the
1114 string in the first examples were anything other than '.', say 'a',
1115 the pattern would not match, because the quoted '.' in the pattern
1116 loses its special meaning of matching any single character.
1117
1118 Bracket expressions in regular expressions can be sources of errors
1119 as well, since characters that are normally special in regular
1120 expressions lose their special meanings between brackets. However,
1121 you can use bracket expressions to match special pattern characters
1122 without quoting them, so they are sometimes useful for this
1123 purpose.
1124
1125 Though it might seem like a strange way to write it, the following
1126 pattern will match a '.' in the string:
1127
1128 [[ . =~ [.] ]]
1129
1130 The shell performs any word expansions before passing the pattern
1131 to the regular expression functions, so you can assume that the
1132 shell's quoting takes precedence. As noted above, the regular
1133 expression parser will interpret any unquoted backslashes remaining
1134 in the pattern after shell expansion according to its own rules.
1135 The intention is to avoid making shell programmers quote things
1136 twice as much as possible, so shell quoting should be sufficient to
1137 quote special pattern characters where that's necessary.
1138
1139 The array variable 'BASH_REMATCH' records which parts of the string
1140 matched the pattern. The element of 'BASH_REMATCH' with index 0
1141 contains the portion of the string matching the entire regular
1142 expression. Substrings matched by parenthesized subexpressions
1143 within the regular expression are saved in the remaining
1144 'BASH_REMATCH' indices. The element of 'BASH_REMATCH' with index N
1145 is the portion of the string matching the Nth parenthesized
1146 subexpression.
1147
1148 Bash sets 'BASH_REMATCH' in the global scope; declaring it as a
1149 local variable will lead to unexpected results.
1150
1151 Expressions may be combined using the following operators, listed
1152 in decreasing order of precedence:
1153
1154 '( EXPRESSION )'
1155 Returns the value of EXPRESSION. This may be used to override
1156 the normal precedence of operators.
1157
1158 '! EXPRESSION'
1159 True if EXPRESSION is false.
1160
1161 'EXPRESSION1 && EXPRESSION2'
1162 True if both EXPRESSION1 and EXPRESSION2 are true.
1163
1164 'EXPRESSION1 || EXPRESSION2'
1165 True if either EXPRESSION1 or EXPRESSION2 is true.
1166
1167 The '&&' and '||' operators do not evaluate EXPRESSION2 if the
1168 value of EXPRESSION1 is sufficient to determine the return value of
1169 the entire conditional expression.
1170
1171\1f
1172File: bashref.info, Node: Command Grouping, Prev: Conditional Constructs, Up: Compound Commands
1173
11743.2.5.3 Grouping Commands
1175.........................
1176
1177Bash provides two ways to group a list of commands to be executed as a
1178unit. When commands are grouped, redirections may be applied to the
1179entire command list. For example, the output of all the commands in the
1180list may be redirected to a single stream.
1181
1182'()'
1183 ( LIST )
1184
1185 Placing a list of commands between parentheses forces the shell to
1186 create a subshell (*note Command Execution Environment::), and each
1187 of the commands in LIST is executed in that subshell environment.
1188 Since the LIST is executed in a subshell, variable assignments do
1189 not remain in effect after the subshell completes.
1190
1191'{}'
1192 { LIST; }
1193
1194 Placing a list of commands between curly braces causes the list to
1195 be executed in the current shell context. No subshell is created.
1196 The semicolon (or newline) following LIST is required.
1197
1198 In addition to the creation of a subshell, there is a subtle
1199difference between these two constructs due to historical reasons. The
1200braces are reserved words, so they must be separated from the LIST by
1201'blank's or other shell metacharacters. The parentheses are operators,
1202and are recognized as separate tokens by the shell even if they are not
1203separated from the LIST by whitespace.
1204
1205 The exit status of both of these constructs is the exit status of
1206LIST.
1207
1208\1f
1209File: bashref.info, Node: Coprocesses, Next: GNU Parallel, Prev: Compound Commands, Up: Shell Commands
1210
12113.2.6 Coprocesses
1212-----------------
1213
1214A 'coprocess' is a shell command preceded by the 'coproc' reserved word.
1215A coprocess is executed asynchronously in a subshell, as if the command
1216had been terminated with the '&' control operator, with a two-way pipe
1217established between the executing shell and the coprocess.
1218
1219 The syntax for a coprocess is:
1220
1221 coproc [NAME] COMMAND [REDIRECTIONS]
1222
1223This creates a coprocess named NAME. COMMAND may be either a simple
1224command (*note Simple Commands::) or a compound command (*note Compound
1225Commands::). NAME is a shell variable name. If NAME is not supplied,
1226the default name is 'COPROC'.
1227
1228 The recommended form to use for a coprocess is
1229
1230 coproc NAME { COMMAND; }
1231
1232This form is recommended because simple commands result in the coprocess
1233always being named 'COPROC', and it is simpler to use and more complete
1234than the other compound commands.
1235
1236 There are other forms of coprocesses:
1237
1238 coproc NAME COMPOUND-COMMAND
1239 coproc COMPOUND-COMMAND
1240 coproc SIMPLE-COMMAND
1241
1242If COMMAND is a compound command, NAME is optional. The word following
1243'coproc' determines whether that word is interpreted as a variable name:
1244it is interpreted as NAME if it is not a reserved word that introduces a
1245compound command. If COMMAND is a simple command, NAME is not allowed;
1246this is to avoid confusion between NAME and the first word of the simple
1247command.
1248
1249 When the coprocess is executed, the shell creates an array variable
1250(*note Arrays::) named NAME in the context of the executing shell. The
1251standard output of COMMAND is connected via a pipe to a file descriptor
1252in the executing shell, and that file descriptor is assigned to NAME[0].
1253The standard input of COMMAND is connected via a pipe to a file
1254descriptor in the executing shell, and that file descriptor is assigned
1255to NAME[1]. This pipe is established before any redirections specified
1256by the command (*note Redirections::). The file descriptors can be
1257utilized as arguments to shell commands and redirections using standard
1258word expansions. Other than those created to execute command and
1259process substitutions, the file descriptors are not available in
1260subshells.
1261
1262 The process ID of the shell spawned to execute the coprocess is
1263available as the value of the variable 'NAME_PID'. The 'wait' builtin
1264command may be used to wait for the coprocess to terminate.
1265
1266 Since the coprocess is created as an asynchronous command, the
1267'coproc' command always returns success. The return status of a
1268coprocess is the exit status of COMMAND.
1269
1270\1f
1271File: bashref.info, Node: GNU Parallel, Prev: Coprocesses, Up: Shell Commands
1272
12733.2.7 GNU Parallel
1274------------------
1275
1276There are ways to run commands in parallel that are not built into Bash.
1277GNU Parallel is a tool to do just that.
1278
1279 GNU Parallel, as its name suggests, can be used to build and run
1280commands in parallel. You may run the same command with different
1281arguments, whether they are filenames, usernames, hostnames, or lines
1282read from files. GNU Parallel provides shorthand references to many of
1283the most common operations (input lines, various portions of the input
1284line, different ways to specify the input source, and so on). Parallel
1285can replace 'xargs' or feed commands from its input sources to several
1286different instances of Bash.
1287
1288 For a complete description, refer to the GNU Parallel documentation,
1289which is available at
1290<https://www.gnu.org/software/parallel/parallel_tutorial.html>.
1291
1292\1f
1293File: bashref.info, Node: Shell Functions, Next: Shell Parameters, Prev: Shell Commands, Up: Basic Shell Features
1294
12953.3 Shell Functions
1296===================
1297
1298Shell functions are a way to group commands for later execution using a
1299single name for the group. They are executed just like a "regular"
1300command. When the name of a shell function is used as a simple command
1301name, the list of commands associated with that function name is
1302executed. Shell functions are executed in the current shell context; no
1303new process is created to interpret them.
1304
1305 Functions are declared using this syntax:
1306 FNAME () COMPOUND-COMMAND [ REDIRECTIONS ]
1307
1308 or
1309
1310 function FNAME [()] COMPOUND-COMMAND [ REDIRECTIONS ]
1311
1312 This defines a shell function named FNAME. The reserved word
1313'function' is optional. If the 'function' reserved word is supplied,
1314the parentheses are optional. The "body" of the function is the
1315compound command COMPOUND-COMMAND (*note Compound Commands::). That
1316command is usually a LIST enclosed between { and }, but may be any
1317compound command listed above. If the 'function' reserved word is used,
1318but the parentheses are not supplied, the braces are recommended.
1319COMPOUND-COMMAND is executed whenever FNAME is specified as the name of
1320a simple command. When the shell is in POSIX mode (*note Bash POSIX
1321Mode::), FNAME must be a valid shell name and may not be the same as one
1322of the special builtins (*note Special Builtins::). In default mode, a
1323function name can be any unquoted shell word that does not contain '$'.
1324Any redirections (*note Redirections::) associated with the shell
1325function are performed when the function is executed. A function
1326definition may be deleted using the '-f' option to the 'unset' builtin
1327(*note Bourne Shell Builtins::).
1328
1329 The exit status of a function definition is zero unless a syntax
1330error occurs or a readonly function with the same name already exists.
1331When executed, the exit status of a function is the exit status of the
1332last command executed in the body.
1333
1334 Note that for historical reasons, in the most common usage the curly
1335braces that surround the body of the function must be separated from the
1336body by 'blank's or newlines. This is because the braces are reserved
1337words and are only recognized as such when they are separated from the
1338command list by whitespace or another shell metacharacter. Also, when
1339using the braces, the LIST must be terminated by a semicolon, a '&', or
1340a newline.
1341
1342 When a function is executed, the arguments to the function become the
1343positional parameters during its execution (*note Positional
1344Parameters::). The special parameter '#' that expands to the number of
1345positional parameters is updated to reflect the change. Special
1346parameter '0' is unchanged. The first element of the 'FUNCNAME'
1347variable is set to the name of the function while the function is
1348executing.
1349
1350 All other aspects of the shell execution environment are identical
1351between a function and its caller with these exceptions: the 'DEBUG' and
1352'RETURN' traps are not inherited unless the function has been given the
1353'trace' attribute using the 'declare' builtin or the '-o functrace'
1354option has been enabled with the 'set' builtin, (in which case all
1355functions inherit the 'DEBUG' and 'RETURN' traps), and the 'ERR' trap is
1356not inherited unless the '-o errtrace' shell option has been enabled.
1357*Note Bourne Shell Builtins::, for the description of the 'trap'
1358builtin.
1359
1360 The 'FUNCNEST' variable, if set to a numeric value greater than 0,
1361defines a maximum function nesting level. Function invocations that
1362exceed the limit cause the entire command to abort.
1363
1364 If the builtin command 'return' is executed in a function, the
1365function completes and execution resumes with the next command after the
1366function call. Any command associated with the 'RETURN' trap is
1367executed before execution resumes. When a function completes, the
1368values of the positional parameters and the special parameter '#' are
1369restored to the values they had prior to the function's execution. If a
1370numeric argument is given to 'return', that is the function's return
1371status; otherwise the function's return status is the exit status of the
1372last command executed before the 'return'.
1373
1374 Variables local to the function may be declared with the 'local'
1375builtin ("local variables"). Ordinarily, variables and their values are
1376shared between a function and its caller. These variables are visible
1377only to the function and the commands it invokes. This is particularly
1378important when a shell function calls other functions.
1379
1380 In the following description, the "current scope" is a currently-
1381executing function. Previous scopes consist of that function's caller
1382and so on, back to the "global" scope, where the shell is not executing
1383any shell function. Consequently, a local variable at the current local
1384scope is a variable declared using the 'local' or 'declare' builtins in
1385the function that is currently executing.
1386
1387 Local variables "shadow" variables with the same name declared at
1388previous scopes. For instance, a local variable declared in a function
1389hides a global variable of the same name: references and assignments
1390refer to the local variable, leaving the global variable unmodified.
1391When the function returns, the global variable is once again visible.
1392
1393 The shell uses "dynamic scoping" to control a variable's visibility
1394within functions. With dynamic scoping, visible variables and their
1395values are a result of the sequence of function calls that caused
1396execution to reach the current function. The value of a variable that a
1397function sees depends on its value within its caller, if any, whether
1398that caller is the "global" scope or another shell function. This is
1399also the value that a local variable declaration "shadows", and the
1400value that is restored when the function returns.
1401
1402 For example, if a variable 'var' is declared as local in function
1403'func1', and 'func1' calls another function 'func2', references to 'var'
1404made from within 'func2' will resolve to the local variable 'var' from
1405'func1', shadowing any global variable named 'var'.
1406
1407 The following script demonstrates this behavior. When executed, the
1408script displays
1409
1410 In func2, var = func1 local
1411
1412 func1()
1413 {
1414 local var='func1 local'
1415 func2
1416 }
1417
1418 func2()
1419 {
1420 echo "In func2, var = $var"
1421 }
1422
1423 var=global
1424 func1
1425
1426 The 'unset' builtin also acts using the same dynamic scope: if a
1427variable is local to the current scope, 'unset' will unset it; otherwise
1428the unset will refer to the variable found in any calling scope as
1429described above. If a variable at the current local scope is unset, it
1430will remain so (appearing as unset) until it is reset in that scope or
1431until the function returns. Once the function returns, any instance of
1432the variable at a previous scope will become visible. If the unset acts
1433on a variable at a previous scope, any instance of a variable with that
1434name that had been shadowed will become visible (see below how
1435'localvar_unset'shell option changes this behavior).
1436
1437 Function names and definitions may be listed with the '-f' option to
1438the 'declare' ('typeset') builtin command (*note Bash Builtins::). The
1439'-F' option to 'declare' or 'typeset' will list the function names only
1440(and optionally the source file and line number, if the 'extdebug' shell
1441option is enabled). Functions may be exported so that child shell
1442processes (those created when executing a separate shell invocation)
1443automatically have them defined with the '-f' option to the 'export'
1444builtin (*note Bourne Shell Builtins::).
1445
1446 Functions may be recursive. The 'FUNCNEST' variable may be used to
1447limit the depth of the function call stack and restrict the number of
1448function invocations. By default, no limit is placed on the number of
1449recursive calls.
1450
1451\1f
1452File: bashref.info, Node: Shell Parameters, Next: Shell Expansions, Prev: Shell Functions, Up: Basic Shell Features
1453
14543.4 Shell Parameters
1455====================
1456
1457* Menu:
1458
1459* Positional Parameters:: The shell's command-line arguments.
1460* Special Parameters:: Parameters denoted by special characters.
1461
1462A "parameter" is an entity that stores values. It can be a 'name', a
1463number, or one of the special characters listed below. A "variable" is
1464a parameter denoted by a 'name'. A variable has a 'value' and zero or
1465more 'attributes'. Attributes are assigned using the 'declare' builtin
1466command (see the description of the 'declare' builtin in *note Bash
1467Builtins::).
1468
1469 A parameter is set if it has been assigned a value. The null string
1470is a valid value. Once a variable is set, it may be unset only by using
1471the 'unset' builtin command.
1472
1473 A variable may be assigned to by a statement of the form
1474 NAME=[VALUE]
1475If VALUE is not given, the variable is assigned the null string. All
1476VALUEs undergo tilde expansion, parameter and variable expansion,
1477command substitution, arithmetic expansion, and quote removal (*note
1478Shell Parameter Expansion::). If the variable has its 'integer'
1479attribute set, then VALUE is evaluated as an arithmetic expression even
1480if the '$((...))' expansion is not used (*note Arithmetic Expansion::).
1481Word splitting and filename expansion are not performed. Assignment
1482statements may also appear as arguments to the 'alias', 'declare',
1483'typeset', 'export', 'readonly', and 'local' builtin commands
1484("declaration" commands). When in POSIX mode (*note Bash POSIX Mode::),
1485these builtins may appear in a command after one or more instances of
1486the 'command' builtin and retain these assignment statement properties.
1487
1488 In the context where an assignment statement is assigning a value to
1489a shell variable or array index (*note Arrays::), the '+=' operator can
1490be used to append to or add to the variable's previous value. This
1491includes arguments to builtin commands such as 'declare' that accept
1492assignment statements (declaration commands). When '+=' is applied to a
1493variable for which the 'integer' attribute has been set, VALUE is
1494evaluated as an arithmetic expression and added to the variable's
1495current value, which is also evaluated. When '+=' is applied to an
1496array variable using compound assignment (*note Arrays::), the
1497variable's value is not unset (as it is when using '='), and new values
1498are appended to the array beginning at one greater than the array's
1499maximum index (for indexed arrays), or added as additional key-value
1500pairs in an associative array. When applied to a string-valued
1501variable, VALUE is expanded and appended to the variable's value.
1502
1503 A variable can be assigned the 'nameref' attribute using the '-n'
1504option to the 'declare' or 'local' builtin commands (*note Bash
1505Builtins::) to create a "nameref", or a reference to another variable.
1506This allows variables to be manipulated indirectly. Whenever the
1507nameref variable is referenced, assigned to, unset, or has its
1508attributes modified (other than using or changing the nameref attribute
1509itself), the operation is actually performed on the variable specified
1510by the nameref variable's value. A nameref is commonly used within
1511shell functions to refer to a variable whose name is passed as an
1512argument to the function. For instance, if a variable name is passed to
1513a shell function as its first argument, running
1514 declare -n ref=$1
1515inside the function creates a nameref variable 'ref' whose value is the
1516variable name passed as the first argument. References and assignments
1517to 'ref', and changes to its attributes, are treated as references,
1518assignments, and attribute modifications to the variable whose name was
1519passed as '$1'.
1520
1521 If the control variable in a 'for' loop has the nameref attribute,
1522the list of words can be a list of shell variables, and a name reference
1523will be established for each word in the list, in turn, when the loop is
1524executed. Array variables cannot be given the nameref attribute.
1525However, nameref variables can reference array variables and subscripted
1526array variables. Namerefs can be unset using the '-n' option to the
1527'unset' builtin (*note Bourne Shell Builtins::). Otherwise, if 'unset'
1528is executed with the name of a nameref variable as an argument, the
1529variable referenced by the nameref variable will be unset.
1530
1531\1f
1532File: bashref.info, Node: Positional Parameters, Next: Special Parameters, Up: Shell Parameters
1533
15343.4.1 Positional Parameters
1535---------------------------
1536
1537A "positional parameter" is a parameter denoted by one or more digits,
1538other than the single digit '0'. Positional parameters are assigned
1539from the shell's arguments when it is invoked, and may be reassigned
1540using the 'set' builtin command. Positional parameter 'N' may be
1541referenced as '${N}', or as '$N' when 'N' consists of a single digit.
1542Positional parameters may not be assigned to with assignment statements.
1543The 'set' and 'shift' builtins are used to set and unset them (*note
1544Shell Builtin Commands::). The positional parameters are temporarily
1545replaced when a shell function is executed (*note Shell Functions::).
1546
1547 When a positional parameter consisting of more than a single digit is
1548expanded, it must be enclosed in braces.
1549
1550\1f
1551File: bashref.info, Node: Special Parameters, Prev: Positional Parameters, Up: Shell Parameters
1552
15533.4.2 Special Parameters
1554------------------------
1555
1556The shell treats several parameters specially. These parameters may
1557only be referenced; assignment to them is not allowed.
1558
1559'*'
1560 ($*) Expands to the positional parameters, starting from one. When
1561 the expansion is not within double quotes, each positional
1562 parameter expands to a separate word. In contexts where it is
1563 performed, those words are subject to further word splitting and
1564 filename expansion. When the expansion occurs within double
1565 quotes, it expands to a single word with the value of each
1566 parameter separated by the first character of the 'IFS' special
1567 variable. That is, '"$*"' is equivalent to '"$1C$2C..."', where C
1568 is the first character of the value of the 'IFS' variable. If
1569 'IFS' is unset, the parameters are separated by spaces. If 'IFS'
1570 is null, the parameters are joined without intervening separators.
1571
1572'@'
1573 ($@) Expands to the positional parameters, starting from one. In
1574 contexts where word splitting is performed, this expands each
1575 positional parameter to a separate word; if not within double
1576 quotes, these words are subject to word splitting. In contexts
1577 where word splitting is not performed, this expands to a single
1578 word with each positional parameter separated by a space. When the
1579 expansion occurs within double quotes, and word splitting is
1580 performed, each parameter expands to a separate word. That is,
1581 '"$@"' is equivalent to '"$1" "$2" ...'. If the double-quoted
1582 expansion occurs within a word, the expansion of the first
1583 parameter is joined with the beginning part of the original word,
1584 and the expansion of the last parameter is joined with the last
1585 part of the original word. When there are no positional
1586 parameters, '"$@"' and '$@' expand to nothing (i.e., they are
1587 removed).
1588
1589'#'
1590 ($#) Expands to the number of positional parameters in decimal.
1591
1592'?'
1593 ($?) Expands to the exit status of the most recently executed
1594 foreground pipeline.
1595
1596'-'
1597 ($-, a hyphen.) Expands to the current option flags as specified
1598 upon invocation, by the 'set' builtin command, or those set by the
1599 shell itself (such as the '-i' option).
1600
1601'$'
1602 ($$) Expands to the process ID of the shell. In a subshell, it
1603 expands to the process ID of the invoking shell, not the subshell.
1604
1605'!'
1606 ($!) Expands to the process ID of the job most recently placed
1607 into the background, whether executed as an asynchronous command or
1608 using the 'bg' builtin (*note Job Control Builtins::).
1609
1610'0'
1611 ($0) Expands to the name of the shell or shell script. This is set
1612 at shell initialization. If Bash is invoked with a file of
1613 commands (*note Shell Scripts::), '$0' is set to the name of that
1614 file. If Bash is started with the '-c' option (*note Invoking
1615 Bash::), then '$0' is set to the first argument after the string to
1616 be executed, if one is present. Otherwise, it is set to the
1617 filename used to invoke Bash, as given by argument zero.
1618
1619\1f
1620File: bashref.info, Node: Shell Expansions, Next: Redirections, Prev: Shell Parameters, Up: Basic Shell Features
1621
16223.5 Shell Expansions
1623====================
1624
1625Expansion is performed on the command line after it has been split into
1626'token's. There are seven kinds of expansion performed:
1627
1628 * brace expansion
1629 * tilde expansion
1630 * parameter and variable expansion
1631 * command substitution
1632 * arithmetic expansion
1633 * word splitting
1634 * filename expansion
1635
1636* Menu:
1637
1638* Brace Expansion:: Expansion of expressions within braces.
1639* Tilde Expansion:: Expansion of the ~ character.
1640* Shell Parameter Expansion:: How Bash expands variables to their values.
1641* Command Substitution:: Using the output of a command as an argument.
1642* Arithmetic Expansion:: How to use arithmetic in shell expansions.
1643* Process Substitution:: A way to write and read to and from a
1644 command.
1645* Word Splitting:: How the results of expansion are split into separate
1646 arguments.
1647* Filename Expansion:: A shorthand for specifying filenames matching patterns.
1648* Quote Removal:: How and when quote characters are removed from
1649 words.
1650
1651 The order of expansions is: brace expansion; tilde expansion,
1652parameter and variable expansion, arithmetic expansion, and command
1653substitution (done in a left-to-right fashion); word splitting; and
1654filename expansion.
1655
1656 On systems that can support it, there is an additional expansion
1657available: "process substitution". This is performed at the same time
1658as tilde, parameter, variable, and arithmetic expansion and command
1659substitution.
1660
1661 After these expansions are performed, quote characters present in the
1662original word are removed unless they have been quoted themselves
1663("quote removal").
1664
1665 Only brace expansion, word splitting, and filename expansion can
1666increase the number of words of the expansion; other expansions expand a
1667single word to a single word. The only exceptions to this are the
1668expansions of '"$@"' and '$*' (*note Special Parameters::), and
1669'"${NAME[@]}"' and '${NAME[*]}' (*note Arrays::).
1670
1671 After all expansions, 'quote removal' (*note Quote Removal::) is
1672performed.
1673
1674\1f
1675File: bashref.info, Node: Brace Expansion, Next: Tilde Expansion, Up: Shell Expansions
1676
16773.5.1 Brace Expansion
1678---------------------
1679
1680Brace expansion is a mechanism by which arbitrary strings may be
1681generated. This mechanism is similar to "filename expansion" (*note
1682Filename Expansion::), but the filenames generated need not exist.
1683Patterns to be brace expanded take the form of an optional PREAMBLE,
1684followed by either a series of comma-separated strings or a sequence
1685expression between a pair of braces, followed by an optional POSTSCRIPT.
1686The preamble is prefixed to each string contained within the braces, and
1687the postscript is then appended to each resulting string, expanding left
1688to right.
1689
1690 Brace expansions may be nested. The results of each expanded string
1691are not sorted; left to right order is preserved. For example,
1692 bash$ echo a{d,c,b}e
1693 ade ace abe
1694
1695 A sequence expression takes the form '{X..Y[..INCR]}', where X and Y
1696are either integers or letters, and INCR, an optional increment, is an
1697integer. When integers are supplied, the expression expands to each
1698number between X and Y, inclusive. Supplied integers may be prefixed
1699with '0' to force each term to have the same width. When either X or Y
1700begins with a zero, the shell attempts to force all generated terms to
1701contain the same number of digits, zero-padding where necessary. When
1702letters are supplied, the expression expands to each character
1703lexicographically between X and Y, inclusive, using the default C
1704locale. Note that both X and Y must be of the same type (integer or
1705letter). When the increment is supplied, it is used as the difference
1706between each term. The default increment is 1 or -1 as appropriate.
1707
1708 Brace expansion is performed before any other expansions, and any
1709characters special to other expansions are preserved in the result. It
1710is strictly textual. Bash does not apply any syntactic interpretation
1711to the context of the expansion or the text between the braces.
1712
1713 A correctly-formed brace expansion must contain unquoted opening and
1714closing braces, and at least one unquoted comma or a valid sequence
1715expression. Any incorrectly formed brace expansion is left unchanged.
1716
1717 A { or ',' may be quoted with a backslash to prevent its being
1718considered part of a brace expression. To avoid conflicts with
1719parameter expansion, the string '${' is not considered eligible for
1720brace expansion, and inhibits brace expansion until the closing '}'.
1721
1722 This construct is typically used as shorthand when the common prefix
1723of the strings to be generated is longer than in the above example:
1724 mkdir /usr/local/src/bash/{old,new,dist,bugs}
1725 or
1726 chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
1727
1728\1f
1729File: bashref.info, Node: Tilde Expansion, Next: Shell Parameter Expansion, Prev: Brace Expansion, Up: Shell Expansions
1730
17313.5.2 Tilde Expansion
1732---------------------
1733
1734If a word begins with an unquoted tilde character ('~'), all of the
1735characters up to the first unquoted slash (or all characters, if there
1736is no unquoted slash) are considered a "tilde-prefix". If none of the
1737characters in the tilde-prefix are quoted, the characters in the
1738tilde-prefix following the tilde are treated as a possible "login name".
1739If this login name is the null string, the tilde is replaced with the
1740value of the 'HOME' shell variable. If 'HOME' is unset, the home
1741directory of the user executing the shell is substituted instead.
1742Otherwise, the tilde-prefix is replaced with the home directory
1743associated with the specified login name.
1744
1745 If the tilde-prefix is '~+', the value of the shell variable 'PWD'
1746replaces the tilde-prefix. If the tilde-prefix is '~-', the value of
1747the shell variable 'OLDPWD', if it is set, is substituted.
1748
1749 If the characters following the tilde in the tilde-prefix consist of
1750a number N, optionally prefixed by a '+' or a '-', the tilde-prefix is
1751replaced with the corresponding element from the directory stack, as it
1752would be displayed by the 'dirs' builtin invoked with the characters
1753following tilde in the tilde-prefix as an argument (*note The Directory
1754Stack::). If the tilde-prefix, sans the tilde, consists of a number
1755without a leading '+' or '-', '+' is assumed.
1756
1757 If the login name is invalid, or the tilde expansion fails, the word
1758is left unchanged.
1759
1760 Each variable assignment is checked for unquoted tilde-prefixes
1761immediately following a ':' or the first '='. In these cases, tilde
1762expansion is also performed. Consequently, one may use filenames with
1763tildes in assignments to 'PATH', 'MAILPATH', and 'CDPATH', and the shell
1764assigns the expanded value.
1765
1766 The following table shows how Bash treats unquoted tilde-prefixes:
1767
1768'~'
1769 The value of '$HOME'
1770'~/foo'
1771 '$HOME/foo'
1772
1773'~fred/foo'
1774 The subdirectory 'foo' of the home directory of the user 'fred'
1775
1776'~+/foo'
1777 '$PWD/foo'
1778
1779'~-/foo'
1780 '${OLDPWD-'~-'}/foo'
1781
1782'~N'
1783 The string that would be displayed by 'dirs +N'
1784
1785'~+N'
1786 The string that would be displayed by 'dirs +N'
1787
1788'~-N'
1789 The string that would be displayed by 'dirs -N'
1790
1791 Bash also performs tilde expansion on words satisfying the conditions
1792of variable assignments (*note Shell Parameters::) when they appear as
1793arguments to simple commands. Bash does not do this, except for the
1794declaration commands listed above, when in POSIX mode.
1795
1796\1f
1797File: bashref.info, Node: Shell Parameter Expansion, Next: Command Substitution, Prev: Tilde Expansion, Up: Shell Expansions
1798
17993.5.3 Shell Parameter Expansion
1800-------------------------------
1801
1802The '$' character introduces parameter expansion, command substitution,
1803or arithmetic expansion. The parameter name or symbol to be expanded
1804may be enclosed in braces, which are optional but serve to protect the
1805variable to be expanded from characters immediately following it which
1806could be interpreted as part of the name.
1807
1808 When braces are used, the matching ending brace is the first '}' not
1809escaped by a backslash or within a quoted string, and not within an
1810embedded arithmetic expansion, command substitution, or parameter
1811expansion.
1812
1813 The basic form of parameter expansion is ${PARAMETER}. The value of
1814PARAMETER is substituted. The PARAMETER is a shell parameter as
1815described above (*note Shell Parameters::) or an array reference (*note
1816Arrays::). The braces are required when PARAMETER is a positional
1817parameter with more than one digit, or when PARAMETER is followed by a
1818character that is not to be interpreted as part of its name.
1819
1820 If the first character of PARAMETER is an exclamation point (!), and
1821PARAMETER is not a nameref, it introduces a level of indirection. Bash
1822uses the value formed by expanding the rest of PARAMETER as the new
1823PARAMETER; this is then expanded and that value is used in the rest of
1824the expansion, rather than the expansion of the original PARAMETER.
1825This is known as 'indirect expansion'. The value is subject to tilde
1826expansion, parameter expansion, command substitution, and arithmetic
1827expansion. If PARAMETER is a nameref, this expands to the name of the
1828variable referenced by PARAMETER instead of performing the complete
1829indirect expansion. The exceptions to this are the expansions of
1830${!PREFIX*} and ${!NAME[@]} described below. The exclamation point must
1831immediately follow the left brace in order to introduce indirection.
1832
1833 In each of the cases below, WORD is subject to tilde expansion,
1834parameter expansion, command substitution, and arithmetic expansion.
1835
1836 When not performing substring expansion, using the form described
1837below (e.g., ':-'), Bash tests for a parameter that is unset or null.
1838Omitting the colon results in a test only for a parameter that is unset.
1839Put another way, if the colon is included, the operator tests for both
1840PARAMETER's existence and that its value is not null; if the colon is
1841omitted, the operator tests only for existence.
1842
1843'${PARAMETER:-WORD}'
1844 If PARAMETER is unset or null, the expansion of WORD is
1845 substituted. Otherwise, the value of PARAMETER is substituted.
1846
1847 $ v=123
1848 $ echo ${v-unset}
1849 123
1850
1851'${PARAMETER:=WORD}'
1852 If PARAMETER is unset or null, the expansion of WORD is assigned to
1853 PARAMETER. The value of PARAMETER is then substituted. Positional
1854 parameters and special parameters may not be assigned to in this
1855 way.
1856
1857 $ var=
1858 $ : ${var:=DEFAULT}
1859 $ echo $var
1860 DEFAULT
1861
1862'${PARAMETER:?WORD}'
1863 If PARAMETER is null or unset, the expansion of WORD (or a message
1864 to that effect if WORD is not present) is written to the standard
1865 error and the shell, if it is not interactive, exits. Otherwise,
1866 the value of PARAMETER is substituted.
1867
1868 $ var=
1869 $ : ${var:?var is unset or null}
1870 bash: var: var is unset or null
1871
1872'${PARAMETER:+WORD}'
1873 If PARAMETER is null or unset, nothing is substituted, otherwise
1874 the expansion of WORD is substituted.
1875
1876 $ var=123
1877 $ echo ${var:+var is set and not null}
1878 var is set and not null
1879
1880'${PARAMETER:OFFSET}'
1881'${PARAMETER:OFFSET:LENGTH}'
1882 This is referred to as Substring Expansion. It expands to up to
1883 LENGTH characters of the value of PARAMETER starting at the
1884 character specified by OFFSET. If PARAMETER is '@' or '*', an
1885 indexed array subscripted by '@' or '*', or an associative array
1886 name, the results differ as described below. If LENGTH is omitted,
1887 it expands to the substring of the value of PARAMETER starting at
1888 the character specified by OFFSET and extending to the end of the
1889 value. LENGTH and OFFSET are arithmetic expressions (*note Shell
1890 Arithmetic::).
1891
1892 If OFFSET evaluates to a number less than zero, the value is used
1893 as an offset in characters from the end of the value of PARAMETER.
1894 If LENGTH evaluates to a number less than zero, it is interpreted
1895 as an offset in characters from the end of the value of PARAMETER
1896 rather than a number of characters, and the expansion is the
1897 characters between OFFSET and that result. Note that a negative
1898 offset must be separated from the colon by at least one space to
1899 avoid being confused with the ':-' expansion.
1900
1901 Here are some examples illustrating substring expansion on
1902 parameters and subscripted arrays:
1903
1904 $ string=01234567890abcdefgh
1905 $ echo ${string:7}
1906 7890abcdefgh
1907 $ echo ${string:7:0}
1908
1909 $ echo ${string:7:2}
1910 78
1911 $ echo ${string:7:-2}
1912 7890abcdef
1913 $ echo ${string: -7}
1914 bcdefgh
1915 $ echo ${string: -7:0}
1916
1917 $ echo ${string: -7:2}
1918 bc
1919 $ echo ${string: -7:-2}
1920 bcdef
1921 $ set -- 01234567890abcdefgh
1922 $ echo ${1:7}
1923 7890abcdefgh
1924 $ echo ${1:7:0}
1925
1926 $ echo ${1:7:2}
1927 78
1928 $ echo ${1:7:-2}
1929 7890abcdef
1930 $ echo ${1: -7}
1931 bcdefgh
1932 $ echo ${1: -7:0}
1933
1934 $ echo ${1: -7:2}
1935 bc
1936 $ echo ${1: -7:-2}
1937 bcdef
1938 $ array[0]=01234567890abcdefgh
1939 $ echo ${array[0]:7}
1940 7890abcdefgh
1941 $ echo ${array[0]:7:0}
1942
1943 $ echo ${array[0]:7:2}
1944 78
1945 $ echo ${array[0]:7:-2}
1946 7890abcdef
1947 $ echo ${array[0]: -7}
1948 bcdefgh
1949 $ echo ${array[0]: -7:0}
1950
1951 $ echo ${array[0]: -7:2}
1952 bc
1953 $ echo ${array[0]: -7:-2}
1954 bcdef
1955
1956 If PARAMETER is '@' or '*', the result is LENGTH positional
1957 parameters beginning at OFFSET. A negative OFFSET is taken
1958 relative to one greater than the greatest positional parameter, so
1959 an offset of -1 evaluates to the last positional parameter. It is
1960 an expansion error if LENGTH evaluates to a number less than zero.
1961
1962 The following examples illustrate substring expansion using
1963 positional parameters:
1964
1965 $ set -- 1 2 3 4 5 6 7 8 9 0 a b c d e f g h
1966 $ echo ${@:7}
1967 7 8 9 0 a b c d e f g h
1968 $ echo ${@:7:0}
1969
1970 $ echo ${@:7:2}
1971 7 8
1972 $ echo ${@:7:-2}
1973 bash: -2: substring expression < 0
1974 $ echo ${@: -7:2}
1975 b c
1976 $ echo ${@:0}
1977 ./bash 1 2 3 4 5 6 7 8 9 0 a b c d e f g h
1978 $ echo ${@:0:2}
1979 ./bash 1
1980 $ echo ${@: -7:0}
1981
1982
1983 If PARAMETER is an indexed array name subscripted by '@' or '*',
1984 the result is the LENGTH members of the array beginning with
1985 '${PARAMETER[OFFSET]}'. A negative OFFSET is taken relative to one
1986 greater than the maximum index of the specified array. It is an
1987 expansion error if LENGTH evaluates to a number less than zero.
1988
1989 These examples show how you can use substring expansion with
1990 indexed arrays:
1991
1992 $ array=(0 1 2 3 4 5 6 7 8 9 0 a b c d e f g h)
1993 $ echo ${array[@]:7}
1994 7 8 9 0 a b c d e f g h
1995 $ echo ${array[@]:7:2}
1996 7 8
1997 $ echo ${array[@]: -7:2}
1998 b c
1999 $ echo ${array[@]: -7:-2}
2000 bash: -2: substring expression < 0
2001 $ echo ${array[@]:0}
2002 0 1 2 3 4 5 6 7 8 9 0 a b c d e f g h
2003 $ echo ${array[@]:0:2}
2004 0 1
2005 $ echo ${array[@]: -7:0}
2006
2007
2008 Substring expansion applied to an associative array produces
2009 undefined results.
2010
2011 Substring indexing is zero-based unless the positional parameters
2012 are used, in which case the indexing starts at 1 by default. If
2013 OFFSET is 0, and the positional parameters are used, '$0' is
2014 prefixed to the list.
2015
2016'${!PREFIX*}'
2017'${!PREFIX@}'
2018 Expands to the names of variables whose names begin with PREFIX,
2019 separated by the first character of the 'IFS' special variable.
2020 When '@' is used and the expansion appears within double quotes,
2021 each variable name expands to a separate word.
2022
2023'${!NAME[@]}'
2024'${!NAME[*]}'
2025 If NAME is an array variable, expands to the list of array indices
2026 (keys) assigned in NAME. If NAME is not an array, expands to 0 if
2027 NAME is set and null otherwise. When '@' is used and the expansion
2028 appears within double quotes, each key expands to a separate word.
2029
2030'${#PARAMETER}'
2031 The length in characters of the expanded value of PARAMETER is
2032 substituted. If PARAMETER is '*' or '@', the value substituted is
2033 the number of positional parameters. If PARAMETER is an array name
2034 subscripted by '*' or '@', the value substituted is the number of
2035 elements in the array. If PARAMETER is an indexed array name
2036 subscripted by a negative number, that number is interpreted as
2037 relative to one greater than the maximum index of PARAMETER, so
2038 negative indices count back from the end of the array, and an index
2039 of -1 references the last element.
2040
2041'${PARAMETER#WORD}'
2042'${PARAMETER##WORD}'
2043 The WORD is expanded to produce a pattern and matched according to
2044 the rules described below (*note Pattern Matching::). If the
2045 pattern matches the beginning of the expanded value of PARAMETER,
2046 then the result of the expansion is the expanded value of PARAMETER
2047 with the shortest matching pattern (the '#' case) or the longest
2048 matching pattern (the '##' case) deleted. If PARAMETER is '@' or
2049 '*', the pattern removal operation is applied to each positional
2050 parameter in turn, and the expansion is the resultant list. If
2051 PARAMETER is an array variable subscripted with '@' or '*', the
2052 pattern removal operation is applied to each member of the array in
2053 turn, and the expansion is the resultant list.
2054
2055'${PARAMETER%WORD}'
2056'${PARAMETER%%WORD}'
2057 The WORD is expanded to produce a pattern and matched according to
2058 the rules described below (*note Pattern Matching::). If the
2059 pattern matches a trailing portion of the expanded value of
2060 PARAMETER, then the result of the expansion is the value of
2061 PARAMETER with the shortest matching pattern (the '%' case) or the
2062 longest matching pattern (the '%%' case) deleted. If PARAMETER is
2063 '@' or '*', the pattern removal operation is applied to each
2064 positional parameter in turn, and the expansion is the resultant
2065 list. If PARAMETER is an array variable subscripted with '@' or
2066 '*', the pattern removal operation is applied to each member of the
2067 array in turn, and the expansion is the resultant list.
2068
2069'${PARAMETER/PATTERN/STRING}'
2070'${PARAMETER//PATTERN/STRING}'
2071'${PARAMETER/#PATTERN/STRING}'
2072'${PARAMETER/%PATTERN/STRING}'
2073 The PATTERN is expanded to produce a pattern just as in filename
2074 expansion. PARAMETER is expanded and the longest match of PATTERN
2075 against its value is replaced with STRING. STRING undergoes tilde
2076 expansion, parameter and variable expansion, arithmetic expansion,
2077 command and process substitution, and quote removal. The match is
2078 performed according to the rules described below (*note Pattern
2079 Matching::).
2080
2081 In the first form above, only the first match is replaced. If
2082 there are two slashes separating PARAMETER and PATTERN (the second
2083 form above), all matches of PATTERN are replaced with STRING. If
2084 PATTERN is preceded by '#' (the third form above), it must match at
2085 the beginning of the expanded value of PARAMETER. If PATTERN is
2086 preceded by '%' (the fourth form above), it must match at the end
2087 of the expanded value of PARAMETER. If the expansion of STRING is
2088 null, matches of PATTERN are deleted. If STRING is null, matches
2089 of PATTERN are deleted and the '/' following PATTERN may be
2090 omitted.
2091
2092 If the 'patsub_replacement' shell option is enabled using 'shopt',
2093 any unquoted instances of '&' in STRING are replaced with the
2094 matching portion of PATTERN. This is intended to duplicate a
2095 common 'sed' idiom.
2096
2097 Quoting any part of STRING inhibits replacement in the expansion of
2098 the quoted portion, including replacement strings stored in shell
2099 variables. Backslash will escape '&' in STRING; the backslash is
2100 removed in order to permit a literal '&' in the replacement string.
2101 Users should take care if STRING is double-quoted to avoid unwanted
2102 interactions between the backslash and double-quoting, since
2103 backslash has special meaning within double quotes. Pattern
2104 substitution performs the check for unquoted '&' after expanding
2105 STRING, so users should ensure to properly quote any occurrences of
2106 '&' they want to be taken literally in the replacement and ensure
2107 any instances of '&' they want to be replaced are unquoted.
2108
2109 For instance,
2110
2111 var=abcdef
2112 rep='& '
2113 echo ${var/abc/& }
2114 echo "${var/abc/& }"
2115 echo ${var/abc/$rep}
2116 echo "${var/abc/$rep}"
2117
2118 will display four lines of "abc def", while
2119
2120 var=abcdef
2121 rep='& '
2122 echo ${var/abc/\& }
2123 echo "${var/abc/\& }"
2124 echo ${var/abc/"& "}
2125 echo ${var/abc/"$rep"}
2126
2127 will display four lines of "& def". Like the pattern removal
2128 operators, double quotes surrounding the replacement string quote
2129 the expanded characters, while double quotes enclosing the entire
2130 parameter substitution do not, since the expansion is performed in
2131 a context that doesn't take any enclosing double quotes into
2132 account.
2133
2134 Since backslash can escape '&', it can also escape a backslash in
2135 the replacement string. This means that '\\' will insert a literal
2136 backslash into the replacement, so these two 'echo' commands
2137
2138 var=abcdef
2139 rep='\\&xyz'
2140 echo ${var/abc/\\&xyz}
2141 echo ${var/abc/$rep}
2142
2143 will both output '\abcxyzdef'.
2144
2145 It should rarely be necessary to enclose only STRING in double
2146 quotes.
2147
2148 If the 'nocasematch' shell option (see the description of 'shopt'
2149 in *note The Shopt Builtin::) is enabled, the match is performed
2150 without regard to the case of alphabetic characters. If PARAMETER
2151 is '@' or '*', the substitution operation is applied to each
2152 positional parameter in turn, and the expansion is the resultant
2153 list. If PARAMETER is an array variable subscripted with '@' or
2154 '*', the substitution operation is applied to each member of the
2155 array in turn, and the expansion is the resultant list.
2156
2157'${PARAMETER^PATTERN}'
2158'${PARAMETER^^PATTERN}'
2159'${PARAMETER,PATTERN}'
2160'${PARAMETER,,PATTERN}'
2161 This expansion modifies the case of alphabetic characters in
2162 PARAMETER. The PATTERN is expanded to produce a pattern just as in
2163 filename expansion. Each character in the expanded value of
2164 PARAMETER is tested against PATTERN, and, if it matches the
2165 pattern, its case is converted. The pattern should not attempt to
2166 match more than one character.
2167
2168 The '^' operator converts lowercase letters matching PATTERN to
2169 uppercase; the ',' operator converts matching uppercase letters to
2170 lowercase. The '^^' and ',,' expansions convert each matched
2171 character in the expanded value; the '^' and ',' expansions match
2172 and convert only the first character in the expanded value. If
2173 PATTERN is omitted, it is treated like a '?', which matches every
2174 character.
2175
2176 If PARAMETER is '@' or '*', the case modification operation is
2177 applied to each positional parameter in turn, and the expansion is
2178 the resultant list. If PARAMETER is an array variable subscripted
2179 with '@' or '*', the case modification operation is applied to each
2180 member of the array in turn, and the expansion is the resultant
2181 list.
2182
2183'${PARAMETER@OPERATOR}'
2184 The expansion is either a transformation of the value of PARAMETER
2185 or information about PARAMETER itself, depending on the value of
2186 OPERATOR. Each OPERATOR is a single letter:
2187
2188 'U'
2189 The expansion is a string that is the value of PARAMETER with
2190 lowercase alphabetic characters converted to uppercase.
2191 'u'
2192 The expansion is a string that is the value of PARAMETER with
2193 the first character converted to uppercase, if it is
2194 alphabetic.
2195 'L'
2196 The expansion is a string that is the value of PARAMETER with
2197 uppercase alphabetic characters converted to lowercase.
2198 'Q'
2199 The expansion is a string that is the value of PARAMETER
2200 quoted in a format that can be reused as input.
2201 'E'
2202 The expansion is a string that is the value of PARAMETER with
2203 backslash escape sequences expanded as with the '$'...''
2204 quoting mechanism.
2205 'P'
2206 The expansion is a string that is the result of expanding the
2207 value of PARAMETER as if it were a prompt string (*note
2208 Controlling the Prompt::).
2209 'A'
2210 The expansion is a string in the form of an assignment
2211 statement or 'declare' command that, if evaluated, will
2212 recreate PARAMETER with its attributes and value.
2213 'K'
2214 Produces a possibly-quoted version of the value of PARAMETER,
2215 except that it prints the values of indexed and associative
2216 arrays as a sequence of quoted key-value pairs (*note
2217 Arrays::).
2218 'a'
2219 The expansion is a string consisting of flag values
2220 representing PARAMETER's attributes.
2221 'k'
2222 Like the 'K' transformation, but expands the keys and values
2223 of indexed and associative arrays to separate words after word
2224 splitting.
2225
2226 If PARAMETER is '@' or '*', the operation is applied to each
2227 positional parameter in turn, and the expansion is the resultant
2228 list. If PARAMETER is an array variable subscripted with '@' or
2229 '*', the operation is applied to each member of the array in turn,
2230 and the expansion is the resultant list.
2231
2232 The result of the expansion is subject to word splitting and
2233 filename expansion as described below.
2234
2235\1f
2236File: bashref.info, Node: Command Substitution, Next: Arithmetic Expansion, Prev: Shell Parameter Expansion, Up: Shell Expansions
2237
22383.5.4 Command Substitution
2239--------------------------
2240
2241Command substitution allows the output of a command to replace the
2242command itself. Command substitution occurs when a command is enclosed
2243as follows:
2244 $(COMMAND)
2245or
2246 `COMMAND`
2247
2248Bash performs the expansion by executing COMMAND in a subshell
2249environment and replacing the command substitution with the standard
2250output of the command, with any trailing newlines deleted. Embedded
2251newlines are not deleted, but they may be removed during word splitting.
2252The command substitution '$(cat FILE)' can be replaced by the equivalent
2253but faster '$(< FILE)'.
2254
2255 When the old-style backquote form of substitution is used, backslash
2256retains its literal meaning except when followed by '$', '`', or '\'.
2257The first backquote not preceded by a backslash terminates the command
2258substitution. When using the '$(COMMAND)' form, all characters between
2259the parentheses make up the command; none are treated specially.
2260
2261 Command substitutions may be nested. To nest when using the
2262backquoted form, escape the inner backquotes with backslashes.
2263
2264 If the substitution appears within double quotes, word splitting and
2265filename expansion are not performed on the results.
2266
2267\1f
2268File: bashref.info, Node: Arithmetic Expansion, Next: Process Substitution, Prev: Command Substitution, Up: Shell Expansions
2269
22703.5.5 Arithmetic Expansion
2271--------------------------
2272
2273Arithmetic expansion allows the evaluation of an arithmetic expression
2274and the substitution of the result. The format for arithmetic expansion
2275is:
2276
2277 $(( EXPRESSION ))
2278
2279 The EXPRESSION undergoes the same expansions as if it were within
2280double quotes, but double quote characters in EXPRESSION are not treated
2281specially and are removed. All tokens in the expression undergo
2282parameter and variable expansion, command substitution, and quote
2283removal. The result is treated as the arithmetic expression to be
2284evaluated. Arithmetic expansions may be nested.
2285
2286 The evaluation is performed according to the rules listed below
2287(*note Shell Arithmetic::). If the expression is invalid, Bash prints a
2288message indicating failure to the standard error and no substitution
2289occurs.
2290
2291\1f
2292File: bashref.info, Node: Process Substitution, Next: Word Splitting, Prev: Arithmetic Expansion, Up: Shell Expansions
2293
22943.5.6 Process Substitution
2295--------------------------
2296
2297Process substitution allows a process's input or output to be referred
2298to using a filename. It takes the form of
2299 <(LIST)
2300or
2301 >(LIST)
2302The process LIST is run asynchronously, and its input or output appears
2303as a filename. This filename is passed as an argument to the current
2304command as the result of the expansion. If the '>(LIST)' form is used,
2305writing to the file will provide input for LIST. If the '<(LIST)' form
2306is used, the file passed as an argument should be read to obtain the
2307output of LIST. Note that no space may appear between the '<' or '>'
2308and the left parenthesis, otherwise the construct would be interpreted
2309as a redirection. Process substitution is supported on systems that
2310support named pipes (FIFOs) or the '/dev/fd' method of naming open
2311files.
2312
2313 When available, process substitution is performed simultaneously with
2314parameter and variable expansion, command substitution, and arithmetic
2315expansion.
2316
2317\1f
2318File: bashref.info, Node: Word Splitting, Next: Filename Expansion, Prev: Process Substitution, Up: Shell Expansions
2319
23203.5.7 Word Splitting
2321--------------------
2322
2323The shell scans the results of parameter expansion, command
2324substitution, and arithmetic expansion that did not occur within double
2325quotes for word splitting.
2326
2327 The shell treats each character of '$IFS' as a delimiter, and splits
2328the results of the other expansions into words using these characters as
2329field terminators. If 'IFS' is unset, or its value is exactly
2330'<space><tab><newline>', the default, then sequences of ' <space>',
2331'<tab>', and '<newline>' at the beginning and end of the results of the
2332previous expansions are ignored, and any sequence of 'IFS' characters
2333not at the beginning or end serves to delimit words. If 'IFS' has a
2334value other than the default, then sequences of the whitespace
2335characters 'space', 'tab', and 'newline' are ignored at the beginning
2336and end of the word, as long as the whitespace character is in the value
2337of 'IFS' (an 'IFS' whitespace character). Any character in 'IFS' that
2338is not 'IFS' whitespace, along with any adjacent 'IFS' whitespace
2339characters, delimits a field. A sequence of 'IFS' whitespace characters
2340is also treated as a delimiter. If the value of 'IFS' is null, no word
2341splitting occurs.
2342
2343 Explicit null arguments ('""' or '''') are retained and passed to
2344commands as empty strings. Unquoted implicit null arguments, resulting
2345from the expansion of parameters that have no values, are removed. If a
2346parameter with no value is expanded within double quotes, a null
2347argument results and is retained and passed to a command as an empty
2348string. When a quoted null argument appears as part of a word whose
2349expansion is non-null, the null argument is removed. That is, the word
2350'-d''' becomes '-d' after word splitting and null argument removal.
2351
2352 Note that if no expansion occurs, no splitting is performed.
2353
2354\1f
2355File: bashref.info, Node: Filename Expansion, Next: Quote Removal, Prev: Word Splitting, Up: Shell Expansions
2356
23573.5.8 Filename Expansion
2358------------------------
2359
2360* Menu:
2361
2362* Pattern Matching:: How the shell matches patterns.
2363
2364After word splitting, unless the '-f' option has been set (*note The Set
2365Builtin::), Bash scans each word for the characters '*', '?', and '['.
2366If one of these characters appears, and is not quoted, then the word is
2367regarded as a PATTERN, and replaced with an alphabetically sorted list
2368of filenames matching the pattern (*note Pattern Matching::). If no
2369matching filenames are found, and the shell option 'nullglob' is
2370disabled, the word is left unchanged. If the 'nullglob' option is set,
2371and no matches are found, the word is removed. If the 'failglob' shell
2372option is set, and no matches are found, an error message is printed and
2373the command is not executed. If the shell option 'nocaseglob' is
2374enabled, the match is performed without regard to the case of alphabetic
2375characters.
2376
2377 When a pattern is used for filename expansion, the character '.' at
2378the start of a filename or immediately following a slash must be matched
2379explicitly, unless the shell option 'dotglob' is set. In order to match
2380the filenames '.' and '..', the pattern must begin with '.' (for
2381example, '.?'), even if 'dotglob' is set. If the 'globskipdots' shell
2382option is enabled, the filenames '.' and '..' are never matched, even if
2383the pattern begins with a '.'. When not matching filenames, the '.'
2384character is not treated specially.
2385
2386 When matching a filename, the slash character must always be matched
2387explicitly by a slash in the pattern, but in other matching contexts it
2388can be matched by a special pattern character as described below (*note
2389Pattern Matching::).
2390
2391 See the description of 'shopt' in *note The Shopt Builtin::, for a
2392description of the 'nocaseglob', 'nullglob', 'globskipdots', 'failglob',
2393and 'dotglob' options.
2394
2395 The 'GLOBIGNORE' shell variable may be used to restrict the set of
2396file names matching a pattern. If 'GLOBIGNORE' is set, each matching
2397file name that also matches one of the patterns in 'GLOBIGNORE' is
2398removed from the list of matches. If the 'nocaseglob' option is set,
2399the matching against the patterns in 'GLOBIGNORE' is performed without
2400regard to case. The filenames '.' and '..' are always ignored when
2401'GLOBIGNORE' is set and not null. However, setting 'GLOBIGNORE' to a
2402non-null value has the effect of enabling the 'dotglob' shell option, so
2403all other filenames beginning with a '.' will match. To get the old
2404behavior of ignoring filenames beginning with a '.', make '.*' one of
2405the patterns in 'GLOBIGNORE'. The 'dotglob' option is disabled when
2406'GLOBIGNORE' is unset.
2407
2408\1f
2409File: bashref.info, Node: Pattern Matching, Up: Filename Expansion
2410
24113.5.8.1 Pattern Matching
2412........................
2413
2414Any character that appears in a pattern, other than the special pattern
2415characters described below, matches itself. The NUL character may not
2416occur in a pattern. A backslash escapes the following character; the
2417escaping backslash is discarded when matching. The special pattern
2418characters must be quoted if they are to be matched literally.
2419
2420 The special pattern characters have the following meanings:
2421'*'
2422 Matches any string, including the null string. When the 'globstar'
2423 shell option is enabled, and '*' is used in a filename expansion
2424 context, two adjacent '*'s used as a single pattern will match all
2425 files and zero or more directories and subdirectories. If followed
2426 by a '/', two adjacent '*'s will match only directories and
2427 subdirectories.
2428'?'
2429 Matches any single character.
2430'[...]'
2431 Matches any one of the enclosed characters. A pair of characters
2432 separated by a hyphen denotes a RANGE EXPRESSION; any character
2433 that falls between those two characters, inclusive, using the
2434 current locale's collating sequence and character set, is matched.
2435 If the first character following the '[' is a '!' or a '^' then any
2436 character not enclosed is matched. A '-' may be matched by
2437 including it as the first or last character in the set. A ']' may
2438 be matched by including it as the first character in the set. The
2439 sorting order of characters in range expressions, and the
2440 characters included in the range, are determined by the current
2441 locale and the values of the 'LC_COLLATE' and 'LC_ALL' shell
2442 variables, if set.
2443
2444 For example, in the default C locale, '[a-dx-z]' is equivalent to
2445 '[abcdxyz]'. Many locales sort characters in dictionary order, and
2446 in these locales '[a-dx-z]' is typically not equivalent to
2447 '[abcdxyz]'; it might be equivalent to '[aBbCcDdxYyZz]', for
2448 example. To obtain the traditional interpretation of ranges in
2449 bracket expressions, you can force the use of the C locale by
2450 setting the 'LC_COLLATE' or 'LC_ALL' environment variable to the
2451 value 'C', or enable the 'globasciiranges' shell option.
2452
2453 Within '[' and ']', "character classes" can be specified using the
2454 syntax '[:'CLASS':]', where CLASS is one of the following classes
2455 defined in the POSIX standard:
2456 alnum alpha ascii blank cntrl digit graph lower
2457 print punct space upper word xdigit
2458 A character class matches any character belonging to that class.
2459 The 'word' character class matches letters, digits, and the
2460 character '_'.
2461
2462 Within '[' and ']', an "equivalence class" can be specified using
2463 the syntax '[='C'=]', which matches all characters with the same
2464 collation weight (as defined by the current locale) as the
2465 character C.
2466
2467 Within '[' and ']', the syntax '[.'SYMBOL'.]' matches the collating
2468 symbol SYMBOL.
2469
2470 If the 'extglob' shell option is enabled using the 'shopt' builtin,
2471the shell recognizes several extended pattern matching operators. In
2472the following description, a PATTERN-LIST is a list of one or more
2473patterns separated by a '|'. When matching filenames, the 'dotglob'
2474shell option determines the set of filenames that are tested, as
2475described above. Composite patterns may be formed using one or more of
2476the following sub-patterns:
2477
2478'?(PATTERN-LIST)'
2479 Matches zero or one occurrence of the given patterns.
2480
2481'*(PATTERN-LIST)'
2482 Matches zero or more occurrences of the given patterns.
2483
2484'+(PATTERN-LIST)'
2485 Matches one or more occurrences of the given patterns.
2486
2487'@(PATTERN-LIST)'
2488 Matches one of the given patterns.
2489
2490'!(PATTERN-LIST)'
2491 Matches anything except one of the given patterns.
2492
2493 The 'extglob' option changes the behavior of the parser, since the
2494parentheses are normally treated as operators with syntactic meaning.
2495To ensure that extended matching patterns are parsed correctly, make
2496sure that 'extglob' is enabled before parsing constructs containing the
2497patterns, including shell functions and command substitutions.
2498
2499 When matching filenames, the 'dotglob' shell option determines the
2500set of filenames that are tested: when 'dotglob' is enabled, the set of
2501filenames includes all files beginning with '.', but the filenames '.'
2502and '..' must be matched by a pattern or sub-pattern that begins with a
2503dot; when it is disabled, the set does not include any filenames
2504beginning with "." unless the pattern or sub-pattern begins with a '.'.
2505As above, '.' only has a special meaning when matching filenames.
2506
2507 Complicated extended pattern matching against long strings is slow,
2508especially when the patterns contain alternations and the strings
2509contain multiple matches. Using separate matches against shorter
2510strings, or using arrays of strings instead of a single long string, may
2511be faster.
2512
2513\1f
2514File: bashref.info, Node: Quote Removal, Prev: Filename Expansion, Up: Shell Expansions
2515
25163.5.9 Quote Removal
2517-------------------
2518
2519After the preceding expansions, all unquoted occurrences of the
2520characters '\', ''', and '"' that did not result from one of the above
2521expansions are removed.
2522
2523\1f
2524File: bashref.info, Node: Redirections, Next: Executing Commands, Prev: Shell Expansions, Up: Basic Shell Features
2525
25263.6 Redirections
2527================
2528
2529Before a command is executed, its input and output may be "redirected"
2530using a special notation interpreted by the shell. "Redirection" allows
2531commands' file handles to be duplicated, opened, closed, made to refer
2532to different files, and can change the files the command reads from and
2533writes to. Redirection may also be used to modify file handles in the
2534current shell execution environment. The following redirection
2535operators may precede or appear anywhere within a simple command or may
2536follow a command. Redirections are processed in the order they appear,
2537from left to right.
2538
2539 Each redirection that may be preceded by a file descriptor number may
2540instead be preceded by a word of the form {VARNAME}. In this case, for
2541each redirection operator except >&- and <&-, the shell will allocate a
2542file descriptor greater than 10 and assign it to {VARNAME}. If >&- or
2543<&- is preceded by {VARNAME}, the value of VARNAME defines the file
2544descriptor to close. If {VARNAME} is supplied, the redirection persists
2545beyond the scope of the command, allowing the shell programmer to manage
2546the file descriptor's lifetime manually. The 'varredir_close' shell
2547option manages this behavior (*note The Shopt Builtin::).
2548
2549 In the following descriptions, if the file descriptor number is
2550omitted, and the first character of the redirection operator is '<', the
2551redirection refers to the standard input (file descriptor 0). If the
2552first character of the redirection operator is '>', the redirection
2553refers to the standard output (file descriptor 1).
2554
2555 The word following the redirection operator in the following
2556descriptions, unless otherwise noted, is subjected to brace expansion,
2557tilde expansion, parameter expansion, command substitution, arithmetic
2558expansion, quote removal, filename expansion, and word splitting. If it
2559expands to more than one word, Bash reports an error.
2560
2561 Note that the order of redirections is significant. For example, the
2562command
2563 ls > DIRLIST 2>&1
2564directs both standard output (file descriptor 1) and standard error
2565(file descriptor 2) to the file DIRLIST, while the command
2566 ls 2>&1 > DIRLIST
2567directs only the standard output to file DIRLIST, because the standard
2568error was made a copy of the standard output before the standard output
2569was redirected to DIRLIST.
2570
2571 Bash handles several filenames specially when they are used in
2572redirections, as described in the following table. If the operating
2573system on which Bash is running provides these special files, bash will
2574use them; otherwise it will emulate them internally with the behavior
2575described below.
2576
2577'/dev/fd/FD'
2578 If FD is a valid integer, file descriptor FD is duplicated.
2579
2580'/dev/stdin'
2581 File descriptor 0 is duplicated.
2582
2583'/dev/stdout'
2584 File descriptor 1 is duplicated.
2585
2586'/dev/stderr'
2587 File descriptor 2 is duplicated.
2588
2589'/dev/tcp/HOST/PORT'
2590 If HOST is a valid hostname or Internet address, and PORT is an
2591 integer port number or service name, Bash attempts to open the
2592 corresponding TCP socket.
2593
2594'/dev/udp/HOST/PORT'
2595 If HOST is a valid hostname or Internet address, and PORT is an
2596 integer port number or service name, Bash attempts to open the
2597 corresponding UDP socket.
2598
2599 A failure to open or create a file causes the redirection to fail.
2600
2601 Redirections using file descriptors greater than 9 should be used
2602with care, as they may conflict with file descriptors the shell uses
2603internally.
2604
26053.6.1 Redirecting Input
2606-----------------------
2607
2608Redirection of input causes the file whose name results from the
2609expansion of WORD to be opened for reading on file descriptor 'n', or
2610the standard input (file descriptor 0) if 'n' is not specified.
2611
2612 The general format for redirecting input is:
2613 [N]<WORD
2614
26153.6.2 Redirecting Output
2616------------------------
2617
2618Redirection of output causes the file whose name results from the
2619expansion of WORD to be opened for writing on file descriptor N, or the
2620standard output (file descriptor 1) if N is not specified. If the file
2621does not exist it is created; if it does exist it is truncated to zero
2622size.
2623
2624 The general format for redirecting output is:
2625 [N]>[|]WORD
2626
2627 If the redirection operator is '>', and the 'noclobber' option to the
2628'set' builtin has been enabled, the redirection will fail if the file
2629whose name results from the expansion of WORD exists and is a regular
2630file. If the redirection operator is '>|', or the redirection operator
2631is '>' and the 'noclobber' option is not enabled, the redirection is
2632attempted even if the file named by WORD exists.
2633
26343.6.3 Appending Redirected Output
2635---------------------------------
2636
2637Redirection of output in this fashion causes the file whose name results
2638from the expansion of WORD to be opened for appending on file descriptor
2639N, or the standard output (file descriptor 1) if N is not specified. If
2640the file does not exist it is created.
2641
2642 The general format for appending output is:
2643 [N]>>WORD
2644
26453.6.4 Redirecting Standard Output and Standard Error
2646----------------------------------------------------
2647
2648This construct allows both the standard output (file descriptor 1) and
2649the standard error output (file descriptor 2) to be redirected to the
2650file whose name is the expansion of WORD.
2651
2652 There are two formats for redirecting standard output and standard
2653error:
2654 &>WORD
2655and
2656 >&WORD
2657Of the two forms, the first is preferred. This is semantically
2658equivalent to
2659 >WORD 2>&1
2660 When using the second form, WORD may not expand to a number or '-'.
2661If it does, other redirection operators apply (see Duplicating File
2662Descriptors below) for compatibility reasons.
2663
26643.6.5 Appending Standard Output and Standard Error
2665--------------------------------------------------
2666
2667This construct allows both the standard output (file descriptor 1) and
2668the standard error output (file descriptor 2) to be appended to the file
2669whose name is the expansion of WORD.
2670
2671 The format for appending standard output and standard error is:
2672 &>>WORD
2673This is semantically equivalent to
2674 >>WORD 2>&1
2675 (see Duplicating File Descriptors below).
2676
26773.6.6 Here Documents
2678--------------------
2679
2680This type of redirection instructs the shell to read input from the
2681current source until a line containing only WORD (with no trailing
2682blanks) is seen. All of the lines read up to that point are then used
2683as the standard input (or file descriptor N if N is specified) for a
2684command.
2685
2686 The format of here-documents is:
2687 [N]<<[-]WORD
2688 HERE-DOCUMENT
2689 DELIMITER
2690
2691 No parameter and variable expansion, command substitution, arithmetic
2692expansion, or filename expansion is performed on WORD. If any part of
2693WORD is quoted, the DELIMITER is the result of quote removal on WORD,
2694and the lines in the here-document are not expanded. If WORD is
2695unquoted, all lines of the here-document are subjected to parameter
2696expansion, command substitution, and arithmetic expansion, the character
2697sequence '\newline' is ignored, and '\' must be used to quote the
2698characters '\', '$', and '`'.
2699
2700 If the redirection operator is '<<-', then all leading tab characters
2701are stripped from input lines and the line containing DELIMITER. This
2702allows here-documents within shell scripts to be indented in a natural
2703fashion.
2704
27053.6.7 Here Strings
2706------------------
2707
2708A variant of here documents, the format is:
2709 [N]<<< WORD
2710
2711 The WORD undergoes tilde expansion, parameter and variable expansion,
2712command substitution, arithmetic expansion, and quote removal. Filename
2713expansion and word splitting are not performed. The result is supplied
2714as a single string, with a newline appended, to the command on its
2715standard input (or file descriptor N if N is specified).
2716
27173.6.8 Duplicating File Descriptors
2718----------------------------------
2719
2720The redirection operator
2721 [N]<&WORD
2722is used to duplicate input file descriptors. If WORD expands to one or
2723more digits, the file descriptor denoted by N is made to be a copy of
2724that file descriptor. If the digits in WORD do not specify a file
2725descriptor open for input, a redirection error occurs. If WORD
2726evaluates to '-', file descriptor N is closed. If N is not specified,
2727the standard input (file descriptor 0) is used.
2728
2729 The operator
2730 [N]>&WORD
2731is used similarly to duplicate output file descriptors. If N is not
2732specified, the standard output (file descriptor 1) is used. If the
2733digits in WORD do not specify a file descriptor open for output, a
2734redirection error occurs. If WORD evaluates to '-', file descriptor N
2735is closed. As a special case, if N is omitted, and WORD does not expand
2736to one or more digits or '-', the standard output and standard error are
2737redirected as described previously.
2738
27393.6.9 Moving File Descriptors
2740-----------------------------
2741
2742The redirection operator
2743 [N]<&DIGIT-
2744moves the file descriptor DIGIT to file descriptor N, or the standard
2745input (file descriptor 0) if N is not specified. DIGIT is closed after
2746being duplicated to N.
2747
2748 Similarly, the redirection operator
2749 [N]>&DIGIT-
2750moves the file descriptor DIGIT to file descriptor N, or the standard
2751output (file descriptor 1) if N is not specified.
2752
27533.6.10 Opening File Descriptors for Reading and Writing
2754-------------------------------------------------------
2755
2756The redirection operator
2757 [N]<>WORD
2758causes the file whose name is the expansion of WORD to be opened for
2759both reading and writing on file descriptor N, or on file descriptor 0
2760if N is not specified. If the file does not exist, it is created.
2761
2762\1f
2763File: bashref.info, Node: Executing Commands, Next: Shell Scripts, Prev: Redirections, Up: Basic Shell Features
2764
27653.7 Executing Commands
2766======================
2767
2768* Menu:
2769
2770* Simple Command Expansion:: How Bash expands simple commands before
2771 executing them.
2772* Command Search and Execution:: How Bash finds commands and runs them.
2773* Command Execution Environment:: The environment in which Bash
2774 executes commands that are not
2775 shell builtins.
2776* Environment:: The environment given to a command.
2777* Exit Status:: The status returned by commands and how Bash
2778 interprets it.
2779* Signals:: What happens when Bash or a command it runs
2780 receives a signal.
2781
2782\1f
2783File: bashref.info, Node: Simple Command Expansion, Next: Command Search and Execution, Up: Executing Commands
2784
27853.7.1 Simple Command Expansion
2786------------------------------
2787
2788When a simple command is executed, the shell performs the following
2789expansions, assignments, and redirections, from left to right, in the
2790following order.
2791
2792 1. The words that the parser has marked as variable assignments (those
2793 preceding the command name) and redirections are saved for later
2794 processing.
2795
2796 2. The words that are not variable assignments or redirections are
2797 expanded (*note Shell Expansions::). If any words remain after
2798 expansion, the first word is taken to be the name of the command
2799 and the remaining words are the arguments.
2800
2801 3. Redirections are performed as described above (*note
2802 Redirections::).
2803
2804 4. The text after the '=' in each variable assignment undergoes tilde
2805 expansion, parameter expansion, command substitution, arithmetic
2806 expansion, and quote removal before being assigned to the variable.
2807
2808 If no command name results, the variable assignments affect the
2809current shell environment. In the case of such a command (one that
2810consists only of assignment statements and redirections), assignment
2811statements are performed before redirections. Otherwise, the variables
2812are added to the environment of the executed command and do not affect
2813the current shell environment. If any of the assignments attempts to
2814assign a value to a readonly variable, an error occurs, and the command
2815exits with a non-zero status.
2816
2817 If no command name results, redirections are performed, but do not
2818affect the current shell environment. A redirection error causes the
2819command to exit with a non-zero status.
2820
2821 If there is a command name left after expansion, execution proceeds
2822as described below. Otherwise, the command exits. If one of the
2823expansions contained a command substitution, the exit status of the
2824command is the exit status of the last command substitution performed.
2825If there were no command substitutions, the command exits with a status
2826of zero.
2827
2828\1f
2829File: bashref.info, Node: Command Search and Execution, Next: Command Execution Environment, Prev: Simple Command Expansion, Up: Executing Commands
2830
28313.7.2 Command Search and Execution
2832----------------------------------
2833
2834After a command has been split into words, if it results in a simple
2835command and an optional list of arguments, the following actions are
2836taken.
2837
2838 1. If the command name contains no slashes, the shell attempts to
2839 locate it. If there exists a shell function by that name, that
2840 function is invoked as described in *note Shell Functions::.
2841
2842 2. If the name does not match a function, the shell searches for it in
2843 the list of shell builtins. If a match is found, that builtin is
2844 invoked.
2845
2846 3. If the name is neither a shell function nor a builtin, and contains
2847 no slashes, Bash searches each element of '$PATH' for a directory
2848 containing an executable file by that name. Bash uses a hash table
2849 to remember the full pathnames of executable files to avoid
2850 multiple 'PATH' searches (see the description of 'hash' in *note
2851 Bourne Shell Builtins::). A full search of the directories in
2852 '$PATH' is performed only if the command is not found in the hash
2853 table. If the search is unsuccessful, the shell searches for a
2854 defined shell function named 'command_not_found_handle'. If that
2855 function exists, it is invoked in a separate execution environment
2856 with the original command and the original command's arguments as
2857 its arguments, and the function's exit status becomes the exit
2858 status of that subshell. If that function is not defined, the
2859 shell prints an error message and returns an exit status of 127.
2860
2861 4. If the search is successful, or if the command name contains one or
2862 more slashes, the shell executes the named program in a separate
2863 execution environment. Argument 0 is set to the name given, and
2864 the remaining arguments to the command are set to the arguments
2865 supplied, if any.
2866
2867 5. If this execution fails because the file is not in executable
2868 format, and the file is not a directory, it is assumed to be a
2869 "shell script" and the shell executes it as described in *note
2870 Shell Scripts::.
2871
2872 6. If the command was not begun asynchronously, the shell waits for
2873 the command to complete and collects its exit status.
2874
2875\1f
2876File: bashref.info, Node: Command Execution Environment, Next: Environment, Prev: Command Search and Execution, Up: Executing Commands
2877
28783.7.3 Command Execution Environment
2879-----------------------------------
2880
2881The shell has an "execution environment", which consists of the
2882following:
2883
2884 * open files inherited by the shell at invocation, as modified by
2885 redirections supplied to the 'exec' builtin
2886
2887 * the current working directory as set by 'cd', 'pushd', or 'popd',
2888 or inherited by the shell at invocation
2889
2890 * the file creation mode mask as set by 'umask' or inherited from the
2891 shell's parent
2892
2893 * current traps set by 'trap'
2894
2895 * shell parameters that are set by variable assignment or with 'set'
2896 or inherited from the shell's parent in the environment
2897
2898 * shell functions defined during execution or inherited from the
2899 shell's parent in the environment
2900
2901 * options enabled at invocation (either by default or with
2902 command-line arguments) or by 'set'
2903
2904 * options enabled by 'shopt' (*note The Shopt Builtin::)
2905
2906 * shell aliases defined with 'alias' (*note Aliases::)
2907
2908 * various process IDs, including those of background jobs (*note
2909 Lists::), the value of '$$', and the value of '$PPID'
2910
2911 When a simple command other than a builtin or shell function is to be
2912executed, it is invoked in a separate execution environment that
2913consists of the following. Unless otherwise noted, the values are
2914inherited from the shell.
2915
2916 * the shell's open files, plus any modifications and additions
2917 specified by redirections to the command
2918
2919 * the current working directory
2920
2921 * the file creation mode mask
2922
2923 * shell variables and functions marked for export, along with
2924 variables exported for the command, passed in the environment
2925 (*note Environment::)
2926
2927 * traps caught by the shell are reset to the values inherited from
2928 the shell's parent, and traps ignored by the shell are ignored
2929
2930 A command invoked in this separate environment cannot affect the
2931shell's execution environment.
2932
2933 A "subshell" is a copy of the shell process.
2934
2935 Command substitution, commands grouped with parentheses, and
2936asynchronous commands are invoked in a subshell environment that is a
2937duplicate of the shell environment, except that traps caught by the
2938shell are reset to the values that the shell inherited from its parent
2939at invocation. Builtin commands that are invoked as part of a pipeline
2940are also executed in a subshell environment. Changes made to the
2941subshell environment cannot affect the shell's execution environment.
2942
2943 Subshells spawned to execute command substitutions inherit the value
2944of the '-e' option from the parent shell. When not in POSIX mode, Bash
2945clears the '-e' option in such subshells.
2946
2947 If a command is followed by a '&' and job control is not active, the
2948default standard input for the command is the empty file '/dev/null'.
2949Otherwise, the invoked command inherits the file descriptors of the
2950calling shell as modified by redirections.
2951
2952\1f
2953File: bashref.info, Node: Environment, Next: Exit Status, Prev: Command Execution Environment, Up: Executing Commands
2954
29553.7.4 Environment
2956-----------------
2957
2958When a program is invoked it is given an array of strings called the
2959"environment". This is a list of name-value pairs, of the form
2960'name=value'.
2961
2962 Bash provides several ways to manipulate the environment. On
2963invocation, the shell scans its own environment and creates a parameter
2964for each name found, automatically marking it for 'export' to child
2965processes. Executed commands inherit the environment. The 'export' and
2966'declare -x' commands allow parameters and functions to be added to and
2967deleted from the environment. If the value of a parameter in the
2968environment is modified, the new value becomes part of the environment,
2969replacing the old. The environment inherited by any executed command
2970consists of the shell's initial environment, whose values may be
2971modified in the shell, less any pairs removed by the 'unset' and 'export
2972-n' commands, plus any additions via the 'export' and 'declare -x'
2973commands.
2974
2975 The environment for any simple command or function may be augmented
2976temporarily by prefixing it with parameter assignments, as described in
2977*note Shell Parameters::. These assignment statements affect only the
2978environment seen by that command.
2979
2980 If the '-k' option is set (*note The Set Builtin::), then all
2981parameter assignments are placed in the environment for a command, not
2982just those that precede the command name.
2983
2984 When Bash invokes an external command, the variable '$_' is set to
2985the full pathname of the command and passed to that command in its
2986environment.
2987
2988\1f
2989File: bashref.info, Node: Exit Status, Next: Signals, Prev: Environment, Up: Executing Commands
2990
29913.7.5 Exit Status
2992-----------------
2993
2994The exit status of an executed command is the value returned by the
2995'waitpid' system call or equivalent function. Exit statuses fall
2996between 0 and 255, though, as explained below, the shell may use values
2997above 125 specially. Exit statuses from shell builtins and compound
2998commands are also limited to this range. Under certain circumstances,
2999the shell will use special values to indicate specific failure modes.
3000
3001 For the shell's purposes, a command which exits with a zero exit
3002status has succeeded. A non-zero exit status indicates failure. This
3003seemingly counter-intuitive scheme is used so there is one well-defined
3004way to indicate success and a variety of ways to indicate various
3005failure modes. When a command terminates on a fatal signal whose number
3006is N, Bash uses the value 128+N as the exit status.
3007
3008 If a command is not found, the child process created to execute it
3009returns a status of 127. If a command is found but is not executable,
3010the return status is 126.
3011
3012 If a command fails because of an error during expansion or
3013redirection, the exit status is greater than zero.
3014
3015 The exit status is used by the Bash conditional commands (*note
3016Conditional Constructs::) and some of the list constructs (*note
3017Lists::).
3018
3019 All of the Bash builtins return an exit status of zero if they
3020succeed and a non-zero status on failure, so they may be used by the
3021conditional and list constructs. All builtins return an exit status of
30222 to indicate incorrect usage, generally invalid options or missing
3023arguments.
3024
3025 The exit status of the last command is available in the special
3026parameter $? (*note Special Parameters::).
3027
3028\1f
3029File: bashref.info, Node: Signals, Prev: Exit Status, Up: Executing Commands
3030
30313.7.6 Signals
3032-------------
3033
3034When Bash is interactive, in the absence of any traps, it ignores
3035'SIGTERM' (so that 'kill 0' does not kill an interactive shell), and
3036'SIGINT' is caught and handled (so that the 'wait' builtin is
3037interruptible). When Bash receives a 'SIGINT', it breaks out of any
3038executing loops. In all cases, Bash ignores 'SIGQUIT'. If job control
3039is in effect (*note Job Control::), Bash ignores 'SIGTTIN', 'SIGTTOU',
3040and 'SIGTSTP'.
3041
3042 Non-builtin commands started by Bash have signal handlers set to the
3043values inherited by the shell from its parent. When job control is not
3044in effect, asynchronous commands ignore 'SIGINT' and 'SIGQUIT' in
3045addition to these inherited handlers. Commands run as a result of
3046command substitution ignore the keyboard-generated job control signals
3047'SIGTTIN', 'SIGTTOU', and 'SIGTSTP'.
3048
3049 The shell exits by default upon receipt of a 'SIGHUP'. Before
3050exiting, an interactive shell resends the 'SIGHUP' to all jobs, running
3051or stopped. Stopped jobs are sent 'SIGCONT' to ensure that they receive
3052the 'SIGHUP'. To prevent the shell from sending the 'SIGHUP' signal to
3053a particular job, it should be removed from the jobs table with the
3054'disown' builtin (*note Job Control Builtins::) or marked to not receive
3055'SIGHUP' using 'disown -h'.
3056
3057 If the 'huponexit' shell option has been set with 'shopt' (*note The
3058Shopt Builtin::), Bash sends a 'SIGHUP' to all jobs when an interactive
3059login shell exits.
3060
3061 If Bash is waiting for a command to complete and receives a signal
3062for which a trap has been set, the trap will not be executed until the
3063command completes. When Bash is waiting for an asynchronous command via
3064the 'wait' builtin, the reception of a signal for which a trap has been
3065set will cause the 'wait' builtin to return immediately with an exit
3066status greater than 128, immediately after which the trap is executed.
3067
3068 When job control is not enabled, and Bash is waiting for a foreground
3069command to complete, the shell receives keyboard-generated signals such
3070as 'SIGINT' (usually generated by '^C') that users commonly intend to
3071send to that command. This happens because the shell and the command
3072are in the same process group as the terminal, and '^C' sends 'SIGINT'
3073to all processes in that process group. See *note Job Control::, for a
3074more in-depth discussion of process groups.
3075
3076 When Bash is running without job control enabled and receives
3077'SIGINT' while waiting for a foreground command, it waits until that
3078foreground command terminates and then decides what to do about the
3079'SIGINT':
3080
3081 1. If the command terminates due to the 'SIGINT', Bash concludes that
3082 the user meant to end the entire script, and acts on the 'SIGINT'
3083 (e.g., by running a 'SIGINT' trap or exiting itself);
3084
3085 2. If the pipeline does not terminate due to 'SIGINT', the program
3086 handled the 'SIGINT' itself and did not treat it as a fatal signal.
3087 In that case, Bash does not treat 'SIGINT' as a fatal signal,
3088 either, instead assuming that the 'SIGINT' was used as part of the
3089 program's normal operation (e.g., 'emacs' uses it to abort editing
3090 commands) or deliberately discarded. However, Bash will run any
3091 trap set on 'SIGINT', as it does with any other trapped signal it
3092 receives while it is waiting for the foreground command to
3093 complete, for compatibility.
3094
3095\1f
3096File: bashref.info, Node: Shell Scripts, Prev: Executing Commands, Up: Basic Shell Features
3097
30983.8 Shell Scripts
3099=================
3100
3101A shell script is a text file containing shell commands. When such a
3102file is used as the first non-option argument when invoking Bash, and
3103neither the '-c' nor '-s' option is supplied (*note Invoking Bash::),
3104Bash reads and executes commands from the file, then exits. This mode
3105of operation creates a non-interactive shell. The shell first searches
3106for the file in the current directory, and looks in the directories in
3107'$PATH' if not found there.
3108
3109 When Bash runs a shell script, it sets the special parameter '0' to
3110the name of the file, rather than the name of the shell, and the
3111positional parameters are set to the remaining arguments, if any are
3112given. If no additional arguments are supplied, the positional
3113parameters are unset.
3114
3115 A shell script may be made executable by using the 'chmod' command to
3116turn on the execute bit. When Bash finds such a file while searching
3117the '$PATH' for a command, it creates a new instance of itself to
3118execute it. In other words, executing
3119 filename ARGUMENTS
3120is equivalent to executing
3121 bash filename ARGUMENTS
3122
3123if 'filename' is an executable shell script. This subshell
3124reinitializes itself, so that the effect is as if a new shell had been
3125invoked to interpret the script, with the exception that the locations
3126of commands remembered by the parent (see the description of 'hash' in
3127*note Bourne Shell Builtins::) are retained by the child.
3128
3129 Most versions of Unix make this a part of the operating system's
3130command execution mechanism. If the first line of a script begins with
3131the two characters '#!', the remainder of the line specifies an
3132interpreter for the program and, depending on the operating system, one
3133or more optional arguments for that interpreter. Thus, you can specify
3134Bash, 'awk', Perl, or some other interpreter and write the rest of the
3135script file in that language.
3136
3137 The arguments to the interpreter consist of one or more optional
3138arguments following the interpreter name on the first line of the script
3139file, followed by the name of the script file, followed by the rest of
3140the arguments supplied to the script. The details of how the
3141interpreter line is split into an interpreter name and a set of
3142arguments vary across systems. Bash will perform this action on
3143operating systems that do not handle it themselves. Note that some
3144older versions of Unix limit the interpreter name and a single argument
3145to a maximum of 32 characters, so it's not portable to assume that using
3146more than one argument will work.
3147
3148 Bash scripts often begin with '#! /bin/bash' (assuming that Bash has
3149been installed in '/bin'), since this ensures that Bash will be used to
3150interpret the script, even if it is executed under another shell. It's
3151a common idiom to use 'env' to find 'bash' even if it's been installed
3152in another directory: '#!/usr/bin/env bash' will find the first
3153occurrence of 'bash' in '$PATH'.
3154
3155\1f
3156File: bashref.info, Node: Shell Builtin Commands, Next: Shell Variables, Prev: Basic Shell Features, Up: Top
3157
31584 Shell Builtin Commands
3159************************
3160
3161* Menu:
3162
3163* Bourne Shell Builtins:: Builtin commands inherited from the Bourne
3164 Shell.
3165* Bash Builtins:: Table of builtins specific to Bash.
3166* Modifying Shell Behavior:: Builtins to modify shell attributes and
3167 optional behavior.
3168* Special Builtins:: Builtin commands classified specially by
3169 POSIX.
3170
3171Builtin commands are contained within the shell itself. When the name
3172of a builtin command is used as the first word of a simple command
3173(*note Simple Commands::), the shell executes the command directly,
3174without invoking another program. Builtin commands are necessary to
3175implement functionality impossible or inconvenient to obtain with
3176separate utilities.
3177
3178 This section briefly describes the builtins which Bash inherits from
3179the Bourne Shell, as well as the builtin commands which are unique to or
3180have been extended in Bash.
3181
3182 Several builtin commands are described in other chapters: builtin
3183commands which provide the Bash interface to the job control facilities
3184(*note Job Control Builtins::), the directory stack (*note Directory
3185Stack Builtins::), the command history (*note Bash History Builtins::),
3186and the programmable completion facilities (*note Programmable
3187Completion Builtins::).
3188
3189 Many of the builtins have been extended by POSIX or Bash.
3190
3191 Unless otherwise noted, each builtin command documented as accepting
3192options preceded by '-' accepts '--' to signify the end of the options.
3193The ':', 'true', 'false', and 'test'/'[' builtins do not accept options
3194and do not treat '--' specially. The 'exit', 'logout', 'return',
3195'break', 'continue', 'let', and 'shift' builtins accept and process
3196arguments beginning with '-' without requiring '--'. Other builtins
3197that accept arguments but are not specified as accepting options
3198interpret arguments beginning with '-' as invalid options and require
3199'--' to prevent this interpretation.
3200
3201\1f
3202File: bashref.info, Node: Bourne Shell Builtins, Next: Bash Builtins, Up: Shell Builtin Commands
3203
32044.1 Bourne Shell Builtins
3205=========================
3206
3207The following shell builtin commands are inherited from the Bourne
3208Shell. These commands are implemented as specified by the POSIX
3209standard.
3210
3211': (a colon)'
3212 : [ARGUMENTS]
3213
3214 Do nothing beyond expanding ARGUMENTS and performing redirections.
3215 The return status is zero.
3216
3217'. (a period)'
3218 . FILENAME [ARGUMENTS]
3219
3220 Read and execute commands from the FILENAME argument in the current
3221 shell context. If FILENAME does not contain a slash, the 'PATH'
3222 variable is used to find FILENAME, but FILENAME does not need to be
3223 executable. When Bash is not in POSIX mode, it searches the
3224 current directory if FILENAME is not found in '$PATH'. If any
3225 ARGUMENTS are supplied, they become the positional parameters when
3226 FILENAME is executed. Otherwise the positional parameters are
3227 unchanged. If the '-T' option is enabled, '.' inherits any trap on
3228 'DEBUG'; if it is not, any 'DEBUG' trap string is saved and
3229 restored around the call to '.', and '.' unsets the 'DEBUG' trap
3230 while it executes. If '-T' is not set, and the sourced file
3231 changes the 'DEBUG' trap, the new value is retained when '.'
3232 completes. The return status is the exit status of the last
3233 command executed, or zero if no commands are executed. If FILENAME
3234 is not found, or cannot be read, the return status is non-zero.
3235 This builtin is equivalent to 'source'.
3236
3237'break'
3238 break [N]
3239
3240 Exit from a 'for', 'while', 'until', or 'select' loop. If N is
3241 supplied, the Nth enclosing loop is exited. N must be greater than
3242 or equal to 1. The return status is zero unless N is not greater
3243 than or equal to 1.
3244
3245'cd'
3246 cd [-L|[-P [-e]] [-@] [DIRECTORY]
3247
3248 Change the current working directory to DIRECTORY. If DIRECTORY is
3249 not supplied, the value of the 'HOME' shell variable is used. If
3250 the shell variable 'CDPATH' exists, it is used as a search path:
3251 each directory name in 'CDPATH' is searched for DIRECTORY, with
3252 alternative directory names in 'CDPATH' separated by a colon (':').
3253 If DIRECTORY begins with a slash, 'CDPATH' is not used.
3254
3255 The '-P' option means to not follow symbolic links: symbolic links
3256 are resolved while 'cd' is traversing DIRECTORY and before
3257 processing an instance of '..' in DIRECTORY.
3258
3259 By default, or when the '-L' option is supplied, symbolic links in
3260 DIRECTORY are resolved after 'cd' processes an instance of '..' in
3261 DIRECTORY.
3262
3263 If '..' appears in DIRECTORY, it is processed by removing the
3264 immediately preceding pathname component, back to a slash or the
3265 beginning of DIRECTORY.
3266
3267 If the '-e' option is supplied with '-P' and the current working
3268 directory cannot be successfully determined after a successful
3269 directory change, 'cd' will return an unsuccessful status.
3270
3271 On systems that support it, the '-@' option presents the extended
3272 attributes associated with a file as a directory.
3273
3274 If DIRECTORY is '-', it is converted to '$OLDPWD' before the
3275 directory change is attempted.
3276
3277 If a non-empty directory name from 'CDPATH' is used, or if '-' is
3278 the first argument, and the directory change is successful, the
3279 absolute pathname of the new working directory is written to the
3280 standard output.
3281
3282 If the directory change is successful, 'cd' sets the value of the
3283 'PWD' environment variable to the new directory name, and sets the
3284 'OLDPWD' environment variable to the value of the current working
3285 directory before the change.
3286
3287 The return status is zero if the directory is successfully changed,
3288 non-zero otherwise.
3289
3290'continue'
3291 continue [N]
3292
3293 Resume the next iteration of an enclosing 'for', 'while', 'until',
3294 or 'select' loop. If N is supplied, the execution of the Nth
3295 enclosing loop is resumed. N must be greater than or equal to 1.
3296 The return status is zero unless N is not greater than or equal to
3297 1.
3298
3299'eval'
3300 eval [ARGUMENTS]
3301
3302 The arguments are concatenated together into a single command,
3303 which is then read and executed, and its exit status returned as
3304 the exit status of 'eval'. If there are no arguments or only empty
3305 arguments, the return status is zero.
3306
3307'exec'
3308 exec [-cl] [-a NAME] [COMMAND [ARGUMENTS]]
3309
3310 If COMMAND is supplied, it replaces the shell without creating a
3311 new process. If the '-l' option is supplied, the shell places a
3312 dash at the beginning of the zeroth argument passed to COMMAND.
3313 This is what the 'login' program does. The '-c' option causes
3314 COMMAND to be executed with an empty environment. If '-a' is
3315 supplied, the shell passes NAME as the zeroth argument to COMMAND.
3316 If COMMAND cannot be executed for some reason, a non-interactive
3317 shell exits, unless the 'execfail' shell option is enabled. In
3318 that case, it returns failure. An interactive shell returns
3319 failure if the file cannot be executed. A subshell exits
3320 unconditionally if 'exec' fails. If no COMMAND is specified,
3321 redirections may be used to affect the current shell environment.
3322 If there are no redirection errors, the return status is zero;
3323 otherwise the return status is non-zero.
3324
3325'exit'
3326 exit [N]
3327
3328 Exit the shell, returning a status of N to the shell's parent. If
3329 N is omitted, the exit status is that of the last command executed.
3330 Any trap on 'EXIT' is executed before the shell terminates.
3331
3332'export'
3333 export [-fn] [-p] [NAME[=VALUE]]
3334
3335 Mark each NAME to be passed to child processes in the environment.
3336 If the '-f' option is supplied, the NAMEs refer to shell functions;
3337 otherwise the names refer to shell variables. The '-n' option
3338 means to no longer mark each NAME for export. If no NAMEs are
3339 supplied, or if the '-p' option is given, a list of names of all
3340 exported variables is displayed. The '-p' option displays output
3341 in a form that may be reused as input. If a variable name is
3342 followed by =VALUE, the value of the variable is set to VALUE.
3343
3344 The return status is zero unless an invalid option is supplied, one
3345 of the names is not a valid shell variable name, or '-f' is
3346 supplied with a name that is not a shell function.
3347
3348'getopts'
3349 getopts OPTSTRING NAME [ARG ...]
3350
3351 'getopts' is used by shell scripts to parse positional parameters.
3352 OPTSTRING contains the option characters to be recognized; if a
3353 character is followed by a colon, the option is expected to have an
3354 argument, which should be separated from it by whitespace. The
3355 colon (':') and question mark ('?') may not be used as option
3356 characters. Each time it is invoked, 'getopts' places the next
3357 option in the shell variable NAME, initializing NAME if it does not
3358 exist, and the index of the next argument to be processed into the
3359 variable 'OPTIND'. 'OPTIND' is initialized to 1 each time the
3360 shell or a shell script is invoked. When an option requires an
3361 argument, 'getopts' places that argument into the variable
3362 'OPTARG'. The shell does not reset 'OPTIND' automatically; it must
3363 be manually reset between multiple calls to 'getopts' within the
3364 same shell invocation if a new set of parameters is to be used.
3365
3366 When the end of options is encountered, 'getopts' exits with a
3367 return value greater than zero. 'OPTIND' is set to the index of
3368 the first non-option argument, and NAME is set to '?'.
3369
3370 'getopts' normally parses the positional parameters, but if more
3371 arguments are supplied as ARG values, 'getopts' parses those
3372 instead.
3373
3374 'getopts' can report errors in two ways. If the first character of
3375 OPTSTRING is a colon, SILENT error reporting is used. In normal
3376 operation, diagnostic messages are printed when invalid options or
3377 missing option arguments are encountered. If the variable 'OPTERR'
3378 is set to 0, no error messages will be displayed, even if the first
3379 character of 'optstring' is not a colon.
3380
3381 If an invalid option is seen, 'getopts' places '?' into NAME and,
3382 if not silent, prints an error message and unsets 'OPTARG'. If
3383 'getopts' is silent, the option character found is placed in
3384 'OPTARG' and no diagnostic message is printed.
3385
3386 If a required argument is not found, and 'getopts' is not silent, a
3387 question mark ('?') is placed in NAME, 'OPTARG' is unset, and a
3388 diagnostic message is printed. If 'getopts' is silent, then a
3389 colon (':') is placed in NAME and 'OPTARG' is set to the option
3390 character found.
3391
3392'hash'
3393 hash [-r] [-p FILENAME] [-dt] [NAME]
3394
3395 Each time 'hash' is invoked, it remembers the full pathnames of the
3396 commands specified as NAME arguments, so they need not be searched
3397 for on subsequent invocations. The commands are found by searching
3398 through the directories listed in '$PATH'. Any
3399 previously-remembered pathname is discarded. The '-p' option
3400 inhibits the path search, and FILENAME is used as the location of
3401 NAME. The '-r' option causes the shell to forget all remembered
3402 locations. The '-d' option causes the shell to forget the
3403 remembered location of each NAME. If the '-t' option is supplied,
3404 the full pathname to which each NAME corresponds is printed. If
3405 multiple NAME arguments are supplied with '-t', the NAME is printed
3406 before the hashed full pathname. The '-l' option causes output to
3407 be displayed in a format that may be reused as input. If no
3408 arguments are given, or if only '-l' is supplied, information about
3409 remembered commands is printed. The return status is zero unless a
3410 NAME is not found or an invalid option is supplied.
3411
3412'pwd'
3413 pwd [-LP]
3414
3415 Print the absolute pathname of the current working directory. If
3416 the '-P' option is supplied, the pathname printed will not contain
3417 symbolic links. If the '-L' option is supplied, the pathname
3418 printed may contain symbolic links. The return status is zero
3419 unless an error is encountered while determining the name of the
3420 current directory or an invalid option is supplied.
3421
3422'readonly'
3423 readonly [-aAf] [-p] [NAME[=VALUE]] ...
3424
3425 Mark each NAME as readonly. The values of these names may not be
3426 changed by subsequent assignment. If the '-f' option is supplied,
3427 each NAME refers to a shell function. The '-a' option means each
3428 NAME refers to an indexed array variable; the '-A' option means
3429 each NAME refers to an associative array variable. If both options
3430 are supplied, '-A' takes precedence. If no NAME arguments are
3431 given, or if the '-p' option is supplied, a list of all readonly
3432 names is printed. The other options may be used to restrict the
3433 output to a subset of the set of readonly names. The '-p' option
3434 causes output to be displayed in a format that may be reused as
3435 input. If a variable name is followed by =VALUE, the value of the
3436 variable is set to VALUE. The return status is zero unless an
3437 invalid option is supplied, one of the NAME arguments is not a
3438 valid shell variable or function name, or the '-f' option is
3439 supplied with a name that is not a shell function.
3440
3441'return'
3442 return [N]
3443
3444 Cause a shell function to stop executing and return the value N to
3445 its caller. If N is not supplied, the return value is the exit
3446 status of the last command executed in the function. If 'return'
3447 is executed by a trap handler, the last command used to determine
3448 the status is the last command executed before the trap handler.
3449 If 'return' is executed during a 'DEBUG' trap, the last command
3450 used to determine the status is the last command executed by the
3451 trap handler before 'return' was invoked. 'return' may also be
3452 used to terminate execution of a script being executed with the '.'
3453 ('source') builtin, returning either N or the exit status of the
3454 last command executed within the script as the exit status of the
3455 script. If N is supplied, the return value is its least
3456 significant 8 bits. Any command associated with the 'RETURN' trap
3457 is executed before execution resumes after the function or script.
3458 The return status is non-zero if 'return' is supplied a non-numeric
3459 argument or is used outside a function and not during the execution
3460 of a script by '.' or 'source'.
3461
3462'shift'
3463 shift [N]
3464
3465 Shift the positional parameters to the left by N. The positional
3466 parameters from N+1 ... '$#' are renamed to '$1' ... '$#'-N.
3467 Parameters represented by the numbers '$#' down to '$#'-N+1 are
3468 unset. N must be a non-negative number less than or equal to '$#'.
3469 If N is zero or greater than '$#', the positional parameters are
3470 not changed. If N is not supplied, it is assumed to be 1. The
3471 return status is zero unless N is greater than '$#' or less than
3472 zero, non-zero otherwise.
3473
3474'test'
3475'['
3476 test EXPR
3477
3478 Evaluate a conditional expression EXPR and return a status of 0
3479 (true) or 1 (false). Each operator and operand must be a separate
3480 argument. Expressions are composed of the primaries described
3481 below in *note Bash Conditional Expressions::. 'test' does not
3482 accept any options, nor does it accept and ignore an argument of
3483 '--' as signifying the end of options.
3484
3485 When the '[' form is used, the last argument to the command must be
3486 a ']'.
3487
3488 Expressions may be combined using the following operators, listed
3489 in decreasing order of precedence. The evaluation depends on the
3490 number of arguments; see below. Operator precedence is used when
3491 there are five or more arguments.
3492
3493 '! EXPR'
3494 True if EXPR is false.
3495
3496 '( EXPR )'
3497 Returns the value of EXPR. This may be used to override the
3498 normal precedence of operators.
3499
3500 'EXPR1 -a EXPR2'
3501 True if both EXPR1 and EXPR2 are true.
3502
3503 'EXPR1 -o EXPR2'
3504 True if either EXPR1 or EXPR2 is true.
3505
3506 The 'test' and '[' builtins evaluate conditional expressions using
3507 a set of rules based on the number of arguments.
3508
3509 0 arguments
3510 The expression is false.
3511
3512 1 argument
3513 The expression is true if, and only if, the argument is not
3514 null.
3515
3516 2 arguments
3517 If the first argument is '!', the expression is true if and
3518 only if the second argument is null. If the first argument is
3519 one of the unary conditional operators (*note Bash Conditional
3520 Expressions::), the expression is true if the unary test is
3521 true. If the first argument is not a valid unary operator,
3522 the expression is false.
3523
3524 3 arguments
3525 The following conditions are applied in the order listed.
3526
3527 1. If the second argument is one of the binary conditional
3528 operators (*note Bash Conditional Expressions::), the
3529 result of the expression is the result of the binary test
3530 using the first and third arguments as operands. The
3531 '-a' and '-o' operators are considered binary operators
3532 when there are three arguments.
3533 2. If the first argument is '!', the value is the negation
3534 of the two-argument test using the second and third
3535 arguments.
3536 3. If the first argument is exactly '(' and the third
3537 argument is exactly ')', the result is the one-argument
3538 test of the second argument.
3539 4. Otherwise, the expression is false.
3540
3541 4 arguments
3542 The following conditions are applied in the order listed.
3543
3544 1. If the first argument is '!', the result is the negation
3545 of the three-argument expression composed of the
3546 remaining arguments.
3547 2. If the first argument is exactly '(' and the fourth
3548 argument is exactly ')', the result is the two-argument
3549 test of the second and third arguments.
3550 3. Otherwise, the expression is parsed and evaluated
3551 according to precedence using the rules listed above.
3552
3553 5 or more arguments
3554 The expression is parsed and evaluated according to precedence
3555 using the rules listed above.
3556
3557 When used with 'test' or '[', the '<' and '>' operators sort
3558 lexicographically using ASCII ordering.
3559
3560'times'
3561 times
3562
3563 Print out the user and system times used by the shell and its
3564 children. The return status is zero.
3565
3566'trap'
3567 trap [-lp] [ARG] [SIGSPEC ...]
3568
3569 The commands in ARG are to be read and executed when the shell
3570 receives signal SIGSPEC. If ARG is absent (and there is a single
3571 SIGSPEC) or equal to '-', each specified signal's disposition is
3572 reset to the value it had when the shell was started. If ARG is
3573 the null string, then the signal specified by each SIGSPEC is
3574 ignored by the shell and commands it invokes. If ARG is not
3575 present and '-p' has been supplied, the shell displays the trap
3576 commands associated with each SIGSPEC. If no arguments are
3577 supplied, or only '-p' is given, 'trap' prints the list of commands
3578 associated with each signal number in a form that may be reused as
3579 shell input. The '-l' option causes the shell to print a list of
3580 signal names and their corresponding numbers. Each SIGSPEC is
3581 either a signal name or a signal number. Signal names are case
3582 insensitive and the 'SIG' prefix is optional.
3583
3584 If a SIGSPEC is '0' or 'EXIT', ARG is executed when the shell
3585 exits. If a SIGSPEC is 'DEBUG', the command ARG is executed before
3586 every simple command, 'for' command, 'case' command, 'select'
3587 command, every arithmetic 'for' command, and before the first
3588 command executes in a shell function. Refer to the description of
3589 the 'extdebug' option to the 'shopt' builtin (*note The Shopt
3590 Builtin::) for details of its effect on the 'DEBUG' trap. If a
3591 SIGSPEC is 'RETURN', the command ARG is executed each time a shell
3592 function or a script executed with the '.' or 'source' builtins
3593 finishes executing.
3594
3595 If a SIGSPEC is 'ERR', the command ARG is executed whenever a
3596 pipeline (which may consist of a single simple command), a list, or
3597 a compound command returns a non-zero exit status, subject to the
3598 following conditions. The 'ERR' trap is not executed if the failed
3599 command is part of the command list immediately following an
3600 'until' or 'while' keyword, part of the test following the 'if' or
3601 'elif' reserved words, part of a command executed in a '&&' or '||'
3602 list except the command following the final '&&' or '||', any
3603 command in a pipeline but the last, or if the command's return
3604 status is being inverted using '!'. These are the same conditions
3605 obeyed by the 'errexit' ('-e') option.
3606
3607 Signals ignored upon entry to the shell cannot be trapped or reset.
3608 Trapped signals that are not being ignored are reset to their
3609 original values in a subshell or subshell environment when one is
3610 created.
3611
3612 The return status is zero unless a SIGSPEC does not specify a valid
3613 signal.
3614
3615'umask'
3616 umask [-p] [-S] [MODE]
3617
3618 Set the shell process's file creation mask to MODE. If MODE begins
3619 with a digit, it is interpreted as an octal number; if not, it is
3620 interpreted as a symbolic mode mask similar to that accepted by the
3621 'chmod' command. If MODE is omitted, the current value of the mask
3622 is printed. If the '-S' option is supplied without a MODE
3623 argument, the mask is printed in a symbolic format. If the '-p'
3624 option is supplied, and MODE is omitted, the output is in a form
3625 that may be reused as input. The return status is zero if the mode
3626 is successfully changed or if no MODE argument is supplied, and
3627 non-zero otherwise.
3628
3629 Note that when the mode is interpreted as an octal number, each
3630 number of the umask is subtracted from '7'. Thus, a umask of '022'
3631 results in permissions of '755'.
3632
3633'unset'
3634 unset [-fnv] [NAME]
3635
3636 Remove each variable or function NAME. If the '-v' option is
3637 given, each NAME refers to a shell variable and that variable is
3638 removed. If the '-f' option is given, the NAMEs refer to shell
3639 functions, and the function definition is removed. If the '-n'
3640 option is supplied, and NAME is a variable with the 'nameref'
3641 attribute, NAME will be unset rather than the variable it
3642 references. '-n' has no effect if the '-f' option is supplied. If
3643 no options are supplied, each NAME refers to a variable; if there
3644 is no variable by that name, a function with that name, if any, is
3645 unset. Readonly variables and functions may not be unset. Some
3646 shell variables lose their special behavior if they are unset; such
3647 behavior is noted in the description of the individual variables.
3648 The return status is zero unless a NAME is readonly or may not be
3649 unset.
3650
3651\1f
3652File: bashref.info, Node: Bash Builtins, Next: Modifying Shell Behavior, Prev: Bourne Shell Builtins, Up: Shell Builtin Commands
3653
36544.2 Bash Builtin Commands
3655=========================
3656
3657This section describes builtin commands which are unique to or have been
3658extended in Bash. Some of these commands are specified in the POSIX
3659standard.
3660
3661'alias'
3662 alias [-p] [NAME[=VALUE] ...]
3663
3664 Without arguments or with the '-p' option, 'alias' prints the list
3665 of aliases on the standard output in a form that allows them to be
3666 reused as input. If arguments are supplied, an alias is defined
3667 for each NAME whose VALUE is given. If no VALUE is given, the name
3668 and value of the alias is printed. Aliases are described in *note
3669 Aliases::.
3670
3671'bind'
3672 bind [-m KEYMAP] [-lpsvPSVX]
3673 bind [-m KEYMAP] [-q FUNCTION] [-u FUNCTION] [-r KEYSEQ]
3674 bind [-m KEYMAP] -f FILENAME
3675 bind [-m KEYMAP] -x KEYSEQ:SHELL-COMMAND
3676 bind [-m KEYMAP] KEYSEQ:FUNCTION-NAME
3677 bind [-m KEYMAP] KEYSEQ:READLINE-COMMAND
3678 bind READLINE-COMMAND-LINE
3679
3680 Display current Readline (*note Command Line Editing::) key and
3681 function bindings, bind a key sequence to a Readline function or
3682 macro, or set a Readline variable. Each non-option argument is a
3683 command as it would appear in a Readline initialization file (*note
3684 Readline Init File::), but each binding or command must be passed
3685 as a separate argument; e.g., '"\C-x\C-r":re-read-init-file'.
3686
3687 Options, if supplied, have the following meanings:
3688
3689 '-m KEYMAP'
3690 Use KEYMAP as the keymap to be affected by the subsequent
3691 bindings. Acceptable KEYMAP names are 'emacs',
3692 'emacs-standard', 'emacs-meta', 'emacs-ctlx', 'vi', 'vi-move',
3693 'vi-command', and 'vi-insert'. 'vi' is equivalent to
3694 'vi-command' ('vi-move' is also a synonym); 'emacs' is
3695 equivalent to 'emacs-standard'.
3696
3697 '-l'
3698 List the names of all Readline functions.
3699
3700 '-p'
3701 Display Readline function names and bindings in such a way
3702 that they can be used as input or in a Readline initialization
3703 file.
3704
3705 '-P'
3706 List current Readline function names and bindings.
3707
3708 '-v'
3709 Display Readline variable names and values in such a way that
3710 they can be used as input or in a Readline initialization
3711 file.
3712
3713 '-V'
3714 List current Readline variable names and values.
3715
3716 '-s'
3717 Display Readline key sequences bound to macros and the strings
3718 they output in such a way that they can be used as input or in
3719 a Readline initialization file.
3720
3721 '-S'
3722 Display Readline key sequences bound to macros and the strings
3723 they output.
3724
3725 '-f FILENAME'
3726 Read key bindings from FILENAME.
3727
3728 '-q FUNCTION'
3729 Query about which keys invoke the named FUNCTION.
3730
3731 '-u FUNCTION'
3732 Unbind all keys bound to the named FUNCTION.
3733
3734 '-r KEYSEQ'
3735 Remove any current binding for KEYSEQ.
3736
3737 '-x KEYSEQ:SHELL-COMMAND'
3738 Cause SHELL-COMMAND to be executed whenever KEYSEQ is entered.
3739 When SHELL-COMMAND is executed, the shell sets the
3740 'READLINE_LINE' variable to the contents of the Readline line
3741 buffer and the 'READLINE_POINT' and 'READLINE_MARK' variables
3742 to the current location of the insertion point and the saved
3743 insertion point (the MARK), respectively. The shell assigns
3744 any numeric argument the user supplied to the
3745 'READLINE_ARGUMENT' variable. If there was no argument, that
3746 variable is not set. If the executed command changes the
3747 value of any of 'READLINE_LINE', 'READLINE_POINT', or
3748 'READLINE_MARK', those new values will be reflected in the
3749 editing state.
3750
3751 '-X'
3752 List all key sequences bound to shell commands and the
3753 associated commands in a format that can be reused as input.
3754
3755 The return status is zero unless an invalid option is supplied or
3756 an error occurs.
3757
3758'builtin'
3759 builtin [SHELL-BUILTIN [ARGS]]
3760
3761 Run a shell builtin, passing it ARGS, and return its exit status.
3762 This is useful when defining a shell function with the same name as
3763 a shell builtin, retaining the functionality of the builtin within
3764 the function. The return status is non-zero if SHELL-BUILTIN is
3765 not a shell builtin command.
3766
3767'caller'
3768 caller [EXPR]
3769
3770 Returns the context of any active subroutine call (a shell function
3771 or a script executed with the '.' or 'source' builtins).
3772
3773 Without EXPR, 'caller' displays the line number and source filename
3774 of the current subroutine call. If a non-negative integer is
3775 supplied as EXPR, 'caller' displays the line number, subroutine
3776 name, and source file corresponding to that position in the current
3777 execution call stack. This extra information may be used, for
3778 example, to print a stack trace. The current frame is frame 0.
3779
3780 The return value is 0 unless the shell is not executing a
3781 subroutine call or EXPR does not correspond to a valid position in
3782 the call stack.
3783
3784'command'
3785 command [-pVv] COMMAND [ARGUMENTS ...]
3786
3787 Runs COMMAND with ARGUMENTS ignoring any shell function named
3788 COMMAND. Only shell builtin commands or commands found by
3789 searching the 'PATH' are executed. If there is a shell function
3790 named 'ls', running 'command ls' within the function will execute
3791 the external command 'ls' instead of calling the function
3792 recursively. The '-p' option means to use a default value for
3793 'PATH' that is guaranteed to find all of the standard utilities.
3794 The return status in this case is 127 if COMMAND cannot be found or
3795 an error occurred, and the exit status of COMMAND otherwise.
3796
3797 If either the '-V' or '-v' option is supplied, a description of
3798 COMMAND is printed. The '-v' option causes a single word
3799 indicating the command or file name used to invoke COMMAND to be
3800 displayed; the '-V' option produces a more verbose description. In
3801 this case, the return status is zero if COMMAND is found, and
3802 non-zero if not.
3803
3804'declare'
3805 declare [-aAfFgiIlnrtux] [-p] [NAME[=VALUE] ...]
3806
3807 Declare variables and give them attributes. If no NAMEs are given,
3808 then display the values of variables instead.
3809
3810 The '-p' option will display the attributes and values of each
3811 NAME. When '-p' is used with NAME arguments, additional options,
3812 other than '-f' and '-F', are ignored.
3813
3814 When '-p' is supplied without NAME arguments, 'declare' will
3815 display the attributes and values of all variables having the
3816 attributes specified by the additional options. If no other
3817 options are supplied with '-p', 'declare' will display the
3818 attributes and values of all shell variables. The '-f' option will
3819 restrict the display to shell functions.
3820
3821 The '-F' option inhibits the display of function definitions; only
3822 the function name and attributes are printed. If the 'extdebug'
3823 shell option is enabled using 'shopt' (*note The Shopt Builtin::),
3824 the source file name and line number where each NAME is defined are
3825 displayed as well. '-F' implies '-f'.
3826
3827 The '-g' option forces variables to be created or modified at the
3828 global scope, even when 'declare' is executed in a shell function.
3829 It is ignored in all other cases.
3830
3831 The '-I' option causes local variables to inherit the attributes
3832 (except the 'nameref' attribute) and value of any existing variable
3833 with the same NAME at a surrounding scope. If there is no existing
3834 variable, the local variable is initially unset.
3835
3836 The following options can be used to restrict output to variables
3837 with the specified attributes or to give variables attributes:
3838
3839 '-a'
3840 Each NAME is an indexed array variable (*note Arrays::).
3841
3842 '-A'
3843 Each NAME is an associative array variable (*note Arrays::).
3844
3845 '-f'
3846 Use function names only.
3847
3848 '-i'
3849 The variable is to be treated as an integer; arithmetic
3850 evaluation (*note Shell Arithmetic::) is performed when the
3851 variable is assigned a value.
3852
3853 '-l'
3854 When the variable is assigned a value, all upper-case
3855 characters are converted to lower-case. The upper-case
3856 attribute is disabled.
3857
3858 '-n'
3859 Give each NAME the 'nameref' attribute, making it a name
3860 reference to another variable. That other variable is defined
3861 by the value of NAME. All references, assignments, and
3862 attribute modifications to NAME, except for those using or
3863 changing the '-n' attribute itself, are performed on the
3864 variable referenced by NAME's value. The nameref attribute
3865 cannot be applied to array variables.
3866
3867 '-r'
3868 Make NAMEs readonly. These names cannot then be assigned
3869 values by subsequent assignment statements or unset.
3870
3871 '-t'
3872 Give each NAME the 'trace' attribute. Traced functions
3873 inherit the 'DEBUG' and 'RETURN' traps from the calling shell.
3874 The trace attribute has no special meaning for variables.
3875
3876 '-u'
3877 When the variable is assigned a value, all lower-case
3878 characters are converted to upper-case. The lower-case
3879 attribute is disabled.
3880
3881 '-x'
3882 Mark each NAME for export to subsequent commands via the
3883 environment.
3884
3885 Using '+' instead of '-' turns off the attribute instead, with the
3886 exceptions that '+a' and '+A' may not be used to destroy array
3887 variables and '+r' will not remove the readonly attribute. When
3888 used in a function, 'declare' makes each NAME local, as with the
3889 'local' command, unless the '-g' option is used. If a variable
3890 name is followed by =VALUE, the value of the variable is set to
3891 VALUE.
3892
3893 When using '-a' or '-A' and the compound assignment syntax to
3894 create array variables, additional attributes do not take effect
3895 until subsequent assignments.
3896
3897 The return status is zero unless an invalid option is encountered,
3898 an attempt is made to define a function using '-f foo=bar', an
3899 attempt is made to assign a value to a readonly variable, an
3900 attempt is made to assign a value to an array variable without
3901 using the compound assignment syntax (*note Arrays::), one of the
3902 NAMEs is not a valid shell variable name, an attempt is made to
3903 turn off readonly status for a readonly variable, an attempt is
3904 made to turn off array status for an array variable, or an attempt
3905 is made to display a non-existent function with '-f'.
3906
3907'echo'
3908 echo [-neE] [ARG ...]
3909
3910 Output the ARGs, separated by spaces, terminated with a newline.
3911 The return status is 0 unless a write error occurs. If '-n' is
3912 specified, the trailing newline is suppressed. If the '-e' option
3913 is given, interpretation of the following backslash-escaped
3914 characters is enabled. The '-E' option disables the interpretation
3915 of these escape characters, even on systems where they are
3916 interpreted by default. The 'xpg_echo' shell option may be used to
3917 dynamically determine whether or not 'echo' expands these escape
3918 characters by default. 'echo' does not interpret '--' to mean the
3919 end of options.
3920
3921 'echo' interprets the following escape sequences:
3922 '\a'
3923 alert (bell)
3924 '\b'
3925 backspace
3926 '\c'
3927 suppress further output
3928 '\e'
3929 '\E'
3930 escape
3931 '\f'
3932 form feed
3933 '\n'
3934 new line
3935 '\r'
3936 carriage return
3937 '\t'
3938 horizontal tab
3939 '\v'
3940 vertical tab
3941 '\\'
3942 backslash
3943 '\0NNN'
3944 the eight-bit character whose value is the octal value NNN
3945 (zero to three octal digits)
3946 '\xHH'
3947 the eight-bit character whose value is the hexadecimal value
3948 HH (one or two hex digits)
3949 '\uHHHH'
3950 the Unicode (ISO/IEC 10646) character whose value is the
3951 hexadecimal value HHHH (one to four hex digits)
3952 '\UHHHHHHHH'
3953 the Unicode (ISO/IEC 10646) character whose value is the
3954 hexadecimal value HHHHHHHH (one to eight hex digits)
3955
3956'enable'
3957 enable [-a] [-dnps] [-f FILENAME] [NAME ...]
3958
3959 Enable and disable builtin shell commands. Disabling a builtin
3960 allows a disk command which has the same name as a shell builtin to
3961 be executed without specifying a full pathname, even though the
3962 shell normally searches for builtins before disk commands. If '-n'
3963 is used, the NAMEs become disabled. Otherwise NAMEs are enabled.
3964 For example, to use the 'test' binary found via '$PATH' instead of
3965 the shell builtin version, type 'enable -n test'.
3966
3967 If the '-p' option is supplied, or no NAME arguments appear, a list
3968 of shell builtins is printed. With no other arguments, the list
3969 consists of all enabled shell builtins. The '-a' option means to
3970 list each builtin with an indication of whether or not it is
3971 enabled.
3972
3973 The '-f' option means to load the new builtin command NAME from
3974 shared object FILENAME, on systems that support dynamic loading.
3975 Bash will use the value of the 'BASH_LOADABLES_PATH' variable as a
3976 colon-separated list of directories in which to search for
3977 FILENAME. The default is system-dependent. The '-d' option will
3978 delete a builtin loaded with '-f'.
3979
3980 If there are no options, a list of the shell builtins is displayed.
3981 The '-s' option restricts 'enable' to the POSIX special builtins.
3982 If '-s' is used with '-f', the new builtin becomes a special
3983 builtin (*note Special Builtins::).
3984
3985 If no options are supplied and a NAME is not a shell builtin,
3986 'enable' will attempt to load NAME from a shared object named NAME,
3987 as if the command were 'enable -f NAME NAME'.
3988
3989 The return status is zero unless a NAME is not a shell builtin or
3990 there is an error loading a new builtin from a shared object.
3991
3992'help'
3993 help [-dms] [PATTERN]
3994
3995 Display helpful information about builtin commands. If PATTERN is
3996 specified, 'help' gives detailed help on all commands matching
3997 PATTERN, otherwise a list of the builtins is printed.
3998
3999 Options, if supplied, have the following meanings:
4000
4001 '-d'
4002 Display a short description of each PATTERN
4003 '-m'
4004 Display the description of each PATTERN in a manpage-like
4005 format
4006 '-s'
4007 Display only a short usage synopsis for each PATTERN
4008
4009 The return status is zero unless no command matches PATTERN.
4010
4011'let'
4012 let EXPRESSION [EXPRESSION ...]
4013
4014 The 'let' builtin allows arithmetic to be performed on shell
4015 variables. Each EXPRESSION is evaluated according to the rules
4016 given below in *note Shell Arithmetic::. If the last EXPRESSION
4017 evaluates to 0, 'let' returns 1; otherwise 0 is returned.
4018
4019'local'
4020 local [OPTION] NAME[=VALUE] ...
4021
4022 For each argument, a local variable named NAME is created, and
4023 assigned VALUE. The OPTION can be any of the options accepted by
4024 'declare'. 'local' can only be used within a function; it makes
4025 the variable NAME have a visible scope restricted to that function
4026 and its children. If NAME is '-', the set of shell options is made
4027 local to the function in which 'local' is invoked: shell options
4028 changed using the 'set' builtin inside the function are restored to
4029 their original values when the function returns. The restore is
4030 effected as if a series of 'set' commands were executed to restore
4031 the values that were in place before the function. The return
4032 status is zero unless 'local' is used outside a function, an
4033 invalid NAME is supplied, or NAME is a readonly variable.
4034
4035'logout'
4036 logout [N]
4037
4038 Exit a login shell, returning a status of N to the shell's parent.
4039
4040'mapfile'
4041 mapfile [-d DELIM] [-n COUNT] [-O ORIGIN] [-s COUNT]
4042 [-t] [-u FD] [-C CALLBACK] [-c QUANTUM] [ARRAY]
4043
4044 Read lines from the standard input into the indexed array variable
4045 ARRAY, or from file descriptor FD if the '-u' option is supplied.
4046 The variable 'MAPFILE' is the default ARRAY. Options, if supplied,
4047 have the following meanings:
4048
4049 '-d'
4050 The first character of DELIM is used to terminate each input
4051 line, rather than newline. If DELIM is the empty string,
4052 'mapfile' will terminate a line when it reads a NUL character.
4053 '-n'
4054 Copy at most COUNT lines. If COUNT is 0, all lines are
4055 copied.
4056 '-O'
4057 Begin assigning to ARRAY at index ORIGIN. The default index
4058 is 0.
4059 '-s'
4060 Discard the first COUNT lines read.
4061 '-t'
4062 Remove a trailing DELIM (default newline) from each line read.
4063 '-u'
4064 Read lines from file descriptor FD instead of the standard
4065 input.
4066 '-C'
4067 Evaluate CALLBACK each time QUANTUM lines are read. The '-c'
4068 option specifies QUANTUM.
4069 '-c'
4070 Specify the number of lines read between each call to
4071 CALLBACK.
4072
4073 If '-C' is specified without '-c', the default quantum is 5000.
4074 When CALLBACK is evaluated, it is supplied the index of the next
4075 array element to be assigned and the line to be assigned to that
4076 element as additional arguments. CALLBACK is evaluated after the
4077 line is read but before the array element is assigned.
4078
4079 If not supplied with an explicit origin, 'mapfile' will clear ARRAY
4080 before assigning to it.
4081
4082 'mapfile' returns successfully unless an invalid option or option
4083 argument is supplied, ARRAY is invalid or unassignable, or ARRAY is
4084 not an indexed array.
4085
4086'printf'
4087 printf [-v VAR] FORMAT [ARGUMENTS]
4088
4089 Write the formatted ARGUMENTS to the standard output under the
4090 control of the FORMAT. The '-v' option causes the output to be
4091 assigned to the variable VAR rather than being printed to the
4092 standard output.
4093
4094 The FORMAT is a character string which contains three types of
4095 objects: plain characters, which are simply copied to standard
4096 output, character escape sequences, which are converted and copied
4097 to the standard output, and format specifications, each of which
4098 causes printing of the next successive ARGUMENT. In addition to
4099 the standard 'printf(1)' formats, 'printf' interprets the following
4100 extensions:
4101
4102 '%b'
4103 Causes 'printf' to expand backslash escape sequences in the
4104 corresponding ARGUMENT in the same way as 'echo -e' (*note
4105 Bash Builtins::).
4106 '%q'
4107 Causes 'printf' to output the corresponding ARGUMENT in a
4108 format that can be reused as shell input.
4109 '%Q'
4110 like '%q', but applies any supplied precision to the ARGUMENT
4111 before quoting it.
4112 '%(DATEFMT)T'
4113 Causes 'printf' to output the date-time string resulting from
4114 using DATEFMT as a format string for 'strftime'(3). The
4115 corresponding ARGUMENT is an integer representing the number
4116 of seconds since the epoch. Two special argument values may
4117 be used: -1 represents the current time, and -2 represents the
4118 time the shell was invoked. If no argument is specified,
4119 conversion behaves as if -1 had been given. This is an
4120 exception to the usual 'printf' behavior.
4121
4122 The %b, %q, and %T directives all use the field width and precision
4123 arguments from the format specification and write that many bytes
4124 from (or use that wide a field for) the expanded argument, which
4125 usually contains more characters than the original.
4126
4127 Arguments to non-string format specifiers are treated as C language
4128 constants, except that a leading plus or minus sign is allowed, and
4129 if the leading character is a single or double quote, the value is
4130 the ASCII value of the following character.
4131
4132 The FORMAT is reused as necessary to consume all of the ARGUMENTS.
4133 If the FORMAT requires more ARGUMENTS than are supplied, the extra
4134 format specifications behave as if a zero value or null string, as
4135 appropriate, had been supplied. The return value is zero on
4136 success, non-zero on failure.
4137
4138'read'
4139 read [-ers] [-a ANAME] [-d DELIM] [-i TEXT] [-n NCHARS]
4140 [-N NCHARS] [-p PROMPT] [-t TIMEOUT] [-u FD] [NAME ...]
4141
4142 One line is read from the standard input, or from the file
4143 descriptor FD supplied as an argument to the '-u' option, split
4144 into words as described above in *note Word Splitting::, and the
4145 first word is assigned to the first NAME, the second word to the
4146 second NAME, and so on. If there are more words than names, the
4147 remaining words and their intervening delimiters are assigned to
4148 the last NAME. If there are fewer words read from the input stream
4149 than names, the remaining names are assigned empty values. The
4150 characters in the value of the 'IFS' variable are used to split the
4151 line into words using the same rules the shell uses for expansion
4152 (described above in *note Word Splitting::). The backslash
4153 character '\' may be used to remove any special meaning for the
4154 next character read and for line continuation.
4155
4156 Options, if supplied, have the following meanings:
4157
4158 '-a ANAME'
4159 The words are assigned to sequential indices of the array
4160 variable ANAME, starting at 0. All elements are removed from
4161 ANAME before the assignment. Other NAME arguments are
4162 ignored.
4163
4164 '-d DELIM'
4165 The first character of DELIM is used to terminate the input
4166 line, rather than newline. If DELIM is the empty string,
4167 'read' will terminate a line when it reads a NUL character.
4168
4169 '-e'
4170 Readline (*note Command Line Editing::) is used to obtain the
4171 line. Readline uses the current (or default, if line editing
4172 was not previously active) editing settings, but uses
4173 Readline's default filename completion.
4174
4175 '-i TEXT'
4176 If Readline is being used to read the line, TEXT is placed
4177 into the editing buffer before editing begins.
4178
4179 '-n NCHARS'
4180 'read' returns after reading NCHARS characters rather than
4181 waiting for a complete line of input, but honors a delimiter
4182 if fewer than NCHARS characters are read before the delimiter.
4183
4184 '-N NCHARS'
4185 'read' returns after reading exactly NCHARS characters rather
4186 than waiting for a complete line of input, unless EOF is
4187 encountered or 'read' times out. Delimiter characters
4188 encountered in the input are not treated specially and do not
4189 cause 'read' to return until NCHARS characters are read. The
4190 result is not split on the characters in 'IFS'; the intent is
4191 that the variable is assigned exactly the characters read
4192 (with the exception of backslash; see the '-r' option below).
4193
4194 '-p PROMPT'
4195 Display PROMPT, without a trailing newline, before attempting
4196 to read any input. The prompt is displayed only if input is
4197 coming from a terminal.
4198
4199 '-r'
4200 If this option is given, backslash does not act as an escape
4201 character. The backslash is considered to be part of the
4202 line. In particular, a backslash-newline pair may not then be
4203 used as a line continuation.
4204
4205 '-s'
4206 Silent mode. If input is coming from a terminal, characters
4207 are not echoed.
4208
4209 '-t TIMEOUT'
4210 Cause 'read' to time out and return failure if a complete line
4211 of input (or a specified number of characters) is not read
4212 within TIMEOUT seconds. TIMEOUT may be a decimal number with
4213 a fractional portion following the decimal point. This option
4214 is only effective if 'read' is reading input from a terminal,
4215 pipe, or other special file; it has no effect when reading
4216 from regular files. If 'read' times out, 'read' saves any
4217 partial input read into the specified variable NAME. If
4218 TIMEOUT is 0, 'read' returns immediately, without trying to
4219 read any data. The exit status is 0 if input is available on
4220 the specified file descriptor, or the read will return EOF,
4221 non-zero otherwise. The exit status is greater than 128 if
4222 the timeout is exceeded.
4223
4224 '-u FD'
4225 Read input from file descriptor FD.
4226
4227 If no NAMEs are supplied, the line read, without the ending
4228 delimiter but otherwise unmodified, is assigned to the variable
4229 'REPLY'. The exit status is zero, unless end-of-file is
4230 encountered, 'read' times out (in which case the status is greater
4231 than 128), a variable assignment error (such as assigning to a
4232 readonly variable) occurs, or an invalid file descriptor is
4233 supplied as the argument to '-u'.
4234
4235'readarray'
4236 readarray [-d DELIM] [-n COUNT] [-O ORIGIN] [-s COUNT]
4237 [-t] [-u FD] [-C CALLBACK] [-c QUANTUM] [ARRAY]
4238
4239 Read lines from the standard input into the indexed array variable
4240 ARRAY, or from file descriptor FD if the '-u' option is supplied.
4241
4242 A synonym for 'mapfile'.
4243
4244'source'
4245 source FILENAME
4246
4247 A synonym for '.' (*note Bourne Shell Builtins::).
4248
4249'type'
4250 type [-afptP] [NAME ...]
4251
4252 For each NAME, indicate how it would be interpreted if used as a
4253 command name.
4254
4255 If the '-t' option is used, 'type' prints a single word which is
4256 one of 'alias', 'function', 'builtin', 'file' or 'keyword', if NAME
4257 is an alias, shell function, shell builtin, disk file, or shell
4258 reserved word, respectively. If the NAME is not found, then
4259 nothing is printed, and 'type' returns a failure status.
4260
4261 If the '-p' option is used, 'type' either returns the name of the
4262 disk file that would be executed, or nothing if '-t' would not
4263 return 'file'.
4264
4265 The '-P' option forces a path search for each NAME, even if '-t'
4266 would not return 'file'.
4267
4268 If a command is hashed, '-p' and '-P' print the hashed value, which
4269 is not necessarily the file that appears first in '$PATH'.
4270
4271 If the '-a' option is used, 'type' returns all of the places that
4272 contain an executable named FILE. This includes aliases and
4273 functions, if and only if the '-p' option is not also used.
4274
4275 If the '-f' option is used, 'type' does not attempt to find shell
4276 functions, as with the 'command' builtin.
4277
4278 The return status is zero if all of the NAMEs are found, non-zero
4279 if any are not found.
4280
4281'typeset'
4282 typeset [-afFgrxilnrtux] [-p] [NAME[=VALUE] ...]
4283
4284 The 'typeset' command is supplied for compatibility with the Korn
4285 shell. It is a synonym for the 'declare' builtin command.
4286
4287'ulimit'
4288 ulimit [-HS] -a
4289 ulimit [-HS] [-bcdefiklmnpqrstuvxPRT] [LIMIT]
4290
4291 'ulimit' provides control over the resources available to processes
4292 started by the shell, on systems that allow such control. If an
4293 option is given, it is interpreted as follows:
4294
4295 '-S'
4296 Change and report the soft limit associated with a resource.
4297
4298 '-H'
4299 Change and report the hard limit associated with a resource.
4300
4301 '-a'
4302 All current limits are reported; no limits are set.
4303
4304 '-b'
4305 The maximum socket buffer size.
4306
4307 '-c'
4308 The maximum size of core files created.
4309
4310 '-d'
4311 The maximum size of a process's data segment.
4312
4313 '-e'
4314 The maximum scheduling priority ("nice").
4315
4316 '-f'
4317 The maximum size of files written by the shell and its
4318 children.
4319
4320 '-i'
4321 The maximum number of pending signals.
4322
4323 '-k'
4324 The maximum number of kqueues that may be allocated.
4325
4326 '-l'
4327 The maximum size that may be locked into memory.
4328
4329 '-m'
4330 The maximum resident set size (many systems do not honor this
4331 limit).
4332
4333 '-n'
4334 The maximum number of open file descriptors (most systems do
4335 not allow this value to be set).
4336
4337 '-p'
4338 The pipe buffer size.
4339
4340 '-q'
4341 The maximum number of bytes in POSIX message queues.
4342
4343 '-r'
4344 The maximum real-time scheduling priority.
4345
4346 '-s'
4347 The maximum stack size.
4348
4349 '-t'
4350 The maximum amount of cpu time in seconds.
4351
4352 '-u'
4353 The maximum number of processes available to a single user.
4354
4355 '-v'
4356 The maximum amount of virtual memory available to the shell,
4357 and, on some systems, to its children.
4358
4359 '-x'
4360 The maximum number of file locks.
4361
4362 '-P'
4363 The maximum number of pseudoterminals.
4364
4365 '-R'
4366 The maximum time a real-time process can run before blocking,
4367 in microseconds.
4368
4369 '-T'
4370 The maximum number of threads.
4371
4372 If LIMIT is given, and the '-a' option is not used, LIMIT is the
4373 new value of the specified resource. The special LIMIT values
4374 'hard', 'soft', and 'unlimited' stand for the current hard limit,
4375 the current soft limit, and no limit, respectively. A hard limit
4376 cannot be increased by a non-root user once it is set; a soft limit
4377 may be increased up to the value of the hard limit. Otherwise, the
4378 current value of the soft limit for the specified resource is
4379 printed, unless the '-H' option is supplied. When more than one
4380 resource is specified, the limit name and unit, if appropriate, are
4381 printed before the value. When setting new limits, if neither '-H'
4382 nor '-S' is supplied, both the hard and soft limits are set. If no
4383 option is given, then '-f' is assumed. Values are in 1024-byte
4384 increments, except for '-t', which is in seconds; '-R', which is in
4385 microseconds; '-p', which is in units of 512-byte blocks; '-P',
4386 '-T', '-b', '-k', '-n' and '-u', which are unscaled values; and,
4387 when in POSIX Mode (*note Bash POSIX Mode::), '-c' and '-f', which
4388 are in 512-byte increments.
4389
4390 The return status is zero unless an invalid option or argument is
4391 supplied, or an error occurs while setting a new limit.
4392
4393'unalias'
4394 unalias [-a] [NAME ... ]
4395
4396 Remove each NAME from the list of aliases. If '-a' is supplied,
4397 all aliases are removed. Aliases are described in *note Aliases::.
4398
4399\1f
4400File: bashref.info, Node: Modifying Shell Behavior, Next: Special Builtins, Prev: Bash Builtins, Up: Shell Builtin Commands
4401
44024.3 Modifying Shell Behavior
4403============================
4404
4405* Menu:
4406
4407* The Set Builtin:: Change the values of shell attributes and
4408 positional parameters.
4409* The Shopt Builtin:: Modify shell optional behavior.
4410
4411\1f
4412File: bashref.info, Node: The Set Builtin, Next: The Shopt Builtin, Up: Modifying Shell Behavior
4413
44144.3.1 The Set Builtin
4415---------------------
4416
4417This builtin is so complicated that it deserves its own section. 'set'
4418allows you to change the values of shell options and set the positional
4419parameters, or to display the names and values of shell variables.
4420
4421'set'
4422 set [-abefhkmnptuvxBCEHPT] [-o OPTION-NAME] [--] [-] [ARGUMENT ...]
4423 set [+abefhkmnptuvxBCEHPT] [+o OPTION-NAME] [--] [-] [ARGUMENT ...]
4424
4425 If no options or arguments are supplied, 'set' displays the names
4426 and values of all shell variables and functions, sorted according
4427 to the current locale, in a format that may be reused as input for
4428 setting or resetting the currently-set variables. Read-only
4429 variables cannot be reset. In POSIX mode, only shell variables are
4430 listed.
4431
4432 When options are supplied, they set or unset shell attributes.
4433 Options, if specified, have the following meanings:
4434
4435 '-a'
4436 Each variable or function that is created or modified is given
4437 the export attribute and marked for export to the environment
4438 of subsequent commands.
4439
4440 '-b'
4441 Cause the status of terminated background jobs to be reported
4442 immediately, rather than before printing the next primary
4443 prompt.
4444
4445 '-e'
4446 Exit immediately if a pipeline (*note Pipelines::), which may
4447 consist of a single simple command (*note Simple Commands::),
4448 a list (*note Lists::), or a compound command (*note Compound
4449 Commands::) returns a non-zero status. The shell does not
4450 exit if the command that fails is part of the command list
4451 immediately following a 'while' or 'until' keyword, part of
4452 the test in an 'if' statement, part of any command executed in
4453 a '&&' or '||' list except the command following the final
4454 '&&' or '||', any command in a pipeline but the last, or if
4455 the command's return status is being inverted with '!'. If a
4456 compound command other than a subshell returns a non-zero
4457 status because a command failed while '-e' was being ignored,
4458 the shell does not exit. A trap on 'ERR', if set, is executed
4459 before the shell exits.
4460
4461 This option applies to the shell environment and each subshell
4462 environment separately (*note Command Execution
4463 Environment::), and may cause subshells to exit before
4464 executing all the commands in the subshell.
4465
4466 If a compound command or shell function executes in a context
4467 where '-e' is being ignored, none of the commands executed
4468 within the compound command or function body will be affected
4469 by the '-e' setting, even if '-e' is set and a command returns
4470 a failure status. If a compound command or shell function
4471 sets '-e' while executing in a context where '-e' is ignored,
4472 that setting will not have any effect until the compound
4473 command or the command containing the function call completes.
4474
4475 '-f'
4476 Disable filename expansion (globbing).
4477
4478 '-h'
4479 Locate and remember (hash) commands as they are looked up for
4480 execution. This option is enabled by default.
4481
4482 '-k'
4483 All arguments in the form of assignment statements are placed
4484 in the environment for a command, not just those that precede
4485 the command name.
4486
4487 '-m'
4488 Job control is enabled (*note Job Control::). All processes
4489 run in a separate process group. When a background job
4490 completes, the shell prints a line containing its exit status.
4491
4492 '-n'
4493 Read commands but do not execute them. This may be used to
4494 check a script for syntax errors. This option is ignored by
4495 interactive shells.
4496
4497 '-o OPTION-NAME'
4498
4499 Set the option corresponding to OPTION-NAME:
4500
4501 'allexport'
4502 Same as '-a'.
4503
4504 'braceexpand'
4505 Same as '-B'.
4506
4507 'emacs'
4508 Use an 'emacs'-style line editing interface (*note
4509 Command Line Editing::). This also affects the editing
4510 interface used for 'read -e'.
4511
4512 'errexit'
4513 Same as '-e'.
4514
4515 'errtrace'
4516 Same as '-E'.
4517
4518 'functrace'
4519 Same as '-T'.
4520
4521 'hashall'
4522 Same as '-h'.
4523
4524 'histexpand'
4525 Same as '-H'.
4526
4527 'history'
4528 Enable command history, as described in *note Bash
4529 History Facilities::. This option is on by default in
4530 interactive shells.
4531
4532 'ignoreeof'
4533 An interactive shell will not exit upon reading EOF.
4534
4535 'keyword'
4536 Same as '-k'.
4537
4538 'monitor'
4539 Same as '-m'.
4540
4541 'noclobber'
4542 Same as '-C'.
4543
4544 'noexec'
4545 Same as '-n'.
4546
4547 'noglob'
4548 Same as '-f'.
4549
4550 'nolog'
4551 Currently ignored.
4552
4553 'notify'
4554 Same as '-b'.
4555
4556 'nounset'
4557 Same as '-u'.
4558
4559 'onecmd'
4560 Same as '-t'.
4561
4562 'physical'
4563 Same as '-P'.
4564
4565 'pipefail'
4566 If set, the return value of a pipeline is the value of
4567 the last (rightmost) command to exit with a non-zero
4568 status, or zero if all commands in the pipeline exit
4569 successfully. This option is disabled by default.
4570
4571 'posix'
4572 Change the behavior of Bash where the default operation
4573 differs from the POSIX standard to match the standard
4574 (*note Bash POSIX Mode::). This is intended to make Bash
4575 behave as a strict superset of that standard.
4576
4577 'privileged'
4578 Same as '-p'.
4579
4580 'verbose'
4581 Same as '-v'.
4582
4583 'vi'
4584 Use a 'vi'-style line editing interface. This also
4585 affects the editing interface used for 'read -e'.
4586
4587 'xtrace'
4588 Same as '-x'.
4589
4590 '-p'
4591 Turn on privileged mode. In this mode, the '$BASH_ENV' and
4592 '$ENV' files are not processed, shell functions are not
4593 inherited from the environment, and the 'SHELLOPTS',
4594 'BASHOPTS', 'CDPATH' and 'GLOBIGNORE' variables, if they
4595 appear in the environment, are ignored. If the shell is
4596 started with the effective user (group) id not equal to the
4597 real user (group) id, and the '-p' option is not supplied,
4598 these actions are taken and the effective user id is set to
4599 the real user id. If the '-p' option is supplied at startup,
4600 the effective user id is not reset. Turning this option off
4601 causes the effective user and group ids to be set to the real
4602 user and group ids.
4603
4604 '-r'
4605 Enable restricted shell mode. This option cannot be unset
4606 once it has been set.
4607
4608 '-t'
4609 Exit after reading and executing one command.
4610
4611 '-u'
4612 Treat unset variables and parameters other than the special
4613 parameters '@' or '*', or array variables subscripted with '@'
4614 or '*', as an error when performing parameter expansion. An
4615 error message will be written to the standard error, and a
4616 non-interactive shell will exit.
4617
4618 '-v'
4619 Print shell input lines as they are read.
4620
4621 '-x'
4622 Print a trace of simple commands, 'for' commands, 'case'
4623 commands, 'select' commands, and arithmetic 'for' commands and
4624 their arguments or associated word lists after they are
4625 expanded and before they are executed. The value of the 'PS4'
4626 variable is expanded and the resultant value is printed before
4627 the command and its expanded arguments.
4628
4629 '-B'
4630 The shell will perform brace expansion (*note Brace
4631 Expansion::). This option is on by default.
4632
4633 '-C'
4634 Prevent output redirection using '>', '>&', and '<>' from
4635 overwriting existing files.
4636
4637 '-E'
4638 If set, any trap on 'ERR' is inherited by shell functions,
4639 command substitutions, and commands executed in a subshell
4640 environment. The 'ERR' trap is normally not inherited in such
4641 cases.
4642
4643 '-H'
4644 Enable '!' style history substitution (*note History
4645 Interaction::). This option is on by default for interactive
4646 shells.
4647
4648 '-P'
4649 If set, do not resolve symbolic links when performing commands
4650 such as 'cd' which change the current directory. The physical
4651 directory is used instead. By default, Bash follows the
4652 logical chain of directories when performing commands which
4653 change the current directory.
4654
4655 For example, if '/usr/sys' is a symbolic link to
4656 '/usr/local/sys' then:
4657 $ cd /usr/sys; echo $PWD
4658 /usr/sys
4659 $ cd ..; pwd
4660 /usr
4661
4662 If 'set -P' is on, then:
4663 $ cd /usr/sys; echo $PWD
4664 /usr/local/sys
4665 $ cd ..; pwd
4666 /usr/local
4667
4668 '-T'
4669 If set, any trap on 'DEBUG' and 'RETURN' are inherited by
4670 shell functions, command substitutions, and commands executed
4671 in a subshell environment. The 'DEBUG' and 'RETURN' traps are
4672 normally not inherited in such cases.
4673
4674 '--'
4675 If no arguments follow this option, then the positional
4676 parameters are unset. Otherwise, the positional parameters
4677 are set to the ARGUMENTS, even if some of them begin with a
4678 '-'.
4679
4680 '-'
4681 Signal the end of options, cause all remaining ARGUMENTS to be
4682 assigned to the positional parameters. The '-x' and '-v'
4683 options are turned off. If there are no arguments, the
4684 positional parameters remain unchanged.
4685
4686 Using '+' rather than '-' causes these options to be turned off.
4687 The options can also be used upon invocation of the shell. The
4688 current set of options may be found in '$-'.
4689
4690 The remaining N ARGUMENTS are positional parameters and are
4691 assigned, in order, to '$1', '$2', ... '$N'. The special parameter
4692 '#' is set to N.
4693
4694 The return status is always zero unless an invalid option is
4695 supplied.
4696
4697\1f
4698File: bashref.info, Node: The Shopt Builtin, Prev: The Set Builtin, Up: Modifying Shell Behavior
4699
47004.3.2 The Shopt Builtin
4701-----------------------
4702
4703This builtin allows you to change additional shell optional behavior.
4704
4705'shopt'
4706 shopt [-pqsu] [-o] [OPTNAME ...]
4707
4708 Toggle the values of settings controlling optional shell behavior.
4709 The settings can be either those listed below, or, if the '-o'
4710 option is used, those available with the '-o' option to the 'set'
4711 builtin command (*note The Set Builtin::). With no options, or
4712 with the '-p' option, a list of all settable options is displayed,
4713 with an indication of whether or not each is set; if OPTNAMEs are
4714 supplied, the output is restricted to those options. The '-p'
4715 option causes output to be displayed in a form that may be reused
4716 as input. Other options have the following meanings:
4717
4718 '-s'
4719 Enable (set) each OPTNAME.
4720
4721 '-u'
4722 Disable (unset) each OPTNAME.
4723
4724 '-q'
4725 Suppresses normal output; the return status indicates whether
4726 the OPTNAME is set or unset. If multiple OPTNAME arguments
4727 are given with '-q', the return status is zero if all OPTNAMEs
4728 are enabled; non-zero otherwise.
4729
4730 '-o'
4731 Restricts the values of OPTNAME to be those defined for the
4732 '-o' option to the 'set' builtin (*note The Set Builtin::).
4733
4734 If either '-s' or '-u' is used with no OPTNAME arguments, 'shopt'
4735 shows only those options which are set or unset, respectively.
4736
4737 Unless otherwise noted, the 'shopt' options are disabled (off) by
4738 default.
4739
4740 The return status when listing options is zero if all OPTNAMEs are
4741 enabled, non-zero otherwise. When setting or unsetting options,
4742 the return status is zero unless an OPTNAME is not a valid shell
4743 option.
4744
4745 The list of 'shopt' options is:
4746
4747 'assoc_expand_once'
4748 If set, the shell suppresses multiple evaluation of
4749 associative array subscripts during arithmetic expression
4750 evaluation, while executing builtins that can perform variable
4751 assignments, and while executing builtins that perform array
4752 dereferencing.
4753
4754 'autocd'
4755 If set, a command name that is the name of a directory is
4756 executed as if it were the argument to the 'cd' command. This
4757 option is only used by interactive shells.
4758
4759 'cdable_vars'
4760 If this is set, an argument to the 'cd' builtin command that
4761 is not a directory is assumed to be the name of a variable
4762 whose value is the directory to change to.
4763
4764 'cdspell'
4765 If set, minor errors in the spelling of a directory component
4766 in a 'cd' command will be corrected. The errors checked for
4767 are transposed characters, a missing character, and a
4768 character too many. If a correction is found, the corrected
4769 path is printed, and the command proceeds. This option is
4770 only used by interactive shells.
4771
4772 'checkhash'
4773 If this is set, Bash checks that a command found in the hash
4774 table exists before trying to execute it. If a hashed command
4775 no longer exists, a normal path search is performed.
4776
4777 'checkjobs'
4778 If set, Bash lists the status of any stopped and running jobs
4779 before exiting an interactive shell. If any jobs are running,
4780 this causes the exit to be deferred until a second exit is
4781 attempted without an intervening command (*note Job
4782 Control::). The shell always postpones exiting if any jobs
4783 are stopped.
4784
4785 'checkwinsize'
4786 If set, Bash checks the window size after each external
4787 (non-builtin) command and, if necessary, updates the values of
4788 'LINES' and 'COLUMNS'. This option is enabled by default.
4789
4790 'cmdhist'
4791 If set, Bash attempts to save all lines of a multiple-line
4792 command in the same history entry. This allows easy
4793 re-editing of multi-line commands. This option is enabled by
4794 default, but only has an effect if command history is enabled
4795 (*note Bash History Facilities::).
4796
4797 'compat31'
4798 'compat32'
4799 'compat40'
4800 'compat41'
4801 'compat42'
4802 'compat43'
4803 'compat44'
4804 These control aspects of the shell's compatibility mode (*note
4805 Shell Compatibility Mode::).
4806
4807 'complete_fullquote'
4808 If set, Bash quotes all shell metacharacters in filenames and
4809 directory names when performing completion. If not set, Bash
4810 removes metacharacters such as the dollar sign from the set of
4811 characters that will be quoted in completed filenames when
4812 these metacharacters appear in shell variable references in
4813 words to be completed. This means that dollar signs in
4814 variable names that expand to directories will not be quoted;
4815 however, any dollar signs appearing in filenames will not be
4816 quoted, either. This is active only when bash is using
4817 backslashes to quote completed filenames. This variable is
4818 set by default, which is the default Bash behavior in versions
4819 through 4.2.
4820
4821 'direxpand'
4822 If set, Bash replaces directory names with the results of word
4823 expansion when performing filename completion. This changes
4824 the contents of the Readline editing buffer. If not set, Bash
4825 attempts to preserve what the user typed.
4826
4827 'dirspell'
4828 If set, Bash attempts spelling correction on directory names
4829 during word completion if the directory name initially
4830 supplied does not exist.
4831
4832 'dotglob'
4833 If set, Bash includes filenames beginning with a '.' in the
4834 results of filename expansion. The filenames '.' and '..'
4835 must always be matched explicitly, even if 'dotglob' is set.
4836
4837 'execfail'
4838 If this is set, a non-interactive shell will not exit if it
4839 cannot execute the file specified as an argument to the 'exec'
4840 builtin command. An interactive shell does not exit if 'exec'
4841 fails.
4842
4843 'expand_aliases'
4844 If set, aliases are expanded as described below under Aliases,
4845 *note Aliases::. This option is enabled by default for
4846 interactive shells.
4847
4848 'extdebug'
4849 If set at shell invocation, or in a shell startup file,
4850 arrange to execute the debugger profile before the shell
4851 starts, identical to the '--debugger' option. If set after
4852 invocation, behavior intended for use by debuggers is enabled:
4853
4854 1. The '-F' option to the 'declare' builtin (*note Bash
4855 Builtins::) displays the source file name and line number
4856 corresponding to each function name supplied as an
4857 argument.
4858
4859 2. If the command run by the 'DEBUG' trap returns a non-zero
4860 value, the next command is skipped and not executed.
4861
4862 3. If the command run by the 'DEBUG' trap returns a value of
4863 2, and the shell is executing in a subroutine (a shell
4864 function or a shell script executed by the '.' or
4865 'source' builtins), the shell simulates a call to
4866 'return'.
4867
4868 4. 'BASH_ARGC' and 'BASH_ARGV' are updated as described in
4869 their descriptions (*note Bash Variables::).
4870
4871 5. Function tracing is enabled: command substitution, shell
4872 functions, and subshells invoked with '( COMMAND )'
4873 inherit the 'DEBUG' and 'RETURN' traps.
4874
4875 6. Error tracing is enabled: command substitution, shell
4876 functions, and subshells invoked with '( COMMAND )'
4877 inherit the 'ERR' trap.
4878
4879 'extglob'
4880 If set, the extended pattern matching features described above
4881 (*note Pattern Matching::) are enabled.
4882
4883 'extquote'
4884 If set, '$'STRING'' and '$"STRING"' quoting is performed
4885 within '${PARAMETER}' expansions enclosed in double quotes.
4886 This option is enabled by default.
4887
4888 'failglob'
4889 If set, patterns which fail to match filenames during filename
4890 expansion result in an expansion error.
4891
4892 'force_fignore'
4893 If set, the suffixes specified by the 'FIGNORE' shell variable
4894 cause words to be ignored when performing word completion even
4895 if the ignored words are the only possible completions. *Note
4896 Bash Variables::, for a description of 'FIGNORE'. This option
4897 is enabled by default.
4898
4899 'globasciiranges'
4900 If set, range expressions used in pattern matching bracket
4901 expressions (*note Pattern Matching::) behave as if in the
4902 traditional C locale when performing comparisons. That is,
4903 the current locale's collating sequence is not taken into
4904 account, so 'b' will not collate between 'A' and 'B', and
4905 upper-case and lower-case ASCII characters will collate
4906 together.
4907
4908 'globskipdots'
4909 If set, filename expansion will never match the filenames '.'
4910 and '..', even if the pattern begins with a '.'. This option
4911 is enabled by default.
4912
4913 'globstar'
4914 If set, the pattern '**' used in a filename expansion context
4915 will match all files and zero or more directories and
4916 subdirectories. If the pattern is followed by a '/', only
4917 directories and subdirectories match.
4918
4919 'gnu_errfmt'
4920 If set, shell error messages are written in the standard GNU
4921 error message format.
4922
4923 'histappend'
4924 If set, the history list is appended to the file named by the
4925 value of the 'HISTFILE' variable when the shell exits, rather
4926 than overwriting the file.
4927
4928 'histreedit'
4929 If set, and Readline is being used, a user is given the
4930 opportunity to re-edit a failed history substitution.
4931
4932 'histverify'
4933 If set, and Readline is being used, the results of history
4934 substitution are not immediately passed to the shell parser.
4935 Instead, the resulting line is loaded into the Readline
4936 editing buffer, allowing further modification.
4937
4938 'hostcomplete'
4939 If set, and Readline is being used, Bash will attempt to
4940 perform hostname completion when a word containing a '@' is
4941 being completed (*note Commands For Completion::). This
4942 option is enabled by default.
4943
4944 'huponexit'
4945 If set, Bash will send 'SIGHUP' to all jobs when an
4946 interactive login shell exits (*note Signals::).
4947
4948 'inherit_errexit'
4949 If set, command substitution inherits the value of the
4950 'errexit' option, instead of unsetting it in the subshell
4951 environment. This option is enabled when POSIX mode is
4952 enabled.
4953
4954 'interactive_comments'
4955 Allow a word beginning with '#' to cause that word and all
4956 remaining characters on that line to be ignored in an
4957 interactive shell. This option is enabled by default.
4958
4959 'lastpipe'
4960 If set, and job control is not active, the shell runs the last
4961 command of a pipeline not executed in the background in the
4962 current shell environment.
4963
4964 'lithist'
4965 If enabled, and the 'cmdhist' option is enabled, multi-line
4966 commands are saved to the history with embedded newlines
4967 rather than using semicolon separators where possible.
4968
4969 'localvar_inherit'
4970 If set, local variables inherit the value and attributes of a
4971 variable of the same name that exists at a previous scope
4972 before any new value is assigned. The 'nameref' attribute is
4973 not inherited.
4974
4975 'localvar_unset'
4976 If set, calling 'unset' on local variables in previous
4977 function scopes marks them so subsequent lookups find them
4978 unset until that function returns. This is identical to the
4979 behavior of unsetting local variables at the current function
4980 scope.
4981
4982 'login_shell'
4983 The shell sets this option if it is started as a login shell
4984 (*note Invoking Bash::). The value may not be changed.
4985
4986 'mailwarn'
4987 If set, and a file that Bash is checking for mail has been
4988 accessed since the last time it was checked, the message '"The
4989 mail in MAILFILE has been read"' is displayed.
4990
4991 'no_empty_cmd_completion'
4992 If set, and Readline is being used, Bash will not attempt to
4993 search the 'PATH' for possible completions when completion is
4994 attempted on an empty line.
4995
4996 'nocaseglob'
4997 If set, Bash matches filenames in a case-insensitive fashion
4998 when performing filename expansion.
4999
5000 'nocasematch'
5001 If set, Bash matches patterns in a case-insensitive fashion
5002 when performing matching while executing 'case' or '[['
5003 conditional commands (*note Conditional Constructs::, when
5004 performing pattern substitution word expansions, or when
5005 filtering possible completions as part of programmable
5006 completion.
5007
5008 'noexpand_translation'
5009 If set, Bash encloses the translated results of $"..."
5010 quoting in single quotes instead of double quotes. If the
5011 string is not translated, this has no effect.
5012
5013 'nullglob'
5014 If set, Bash allows filename patterns which match no files to
5015 expand to a null string, rather than themselves.
5016
5017 'patsub_replacement'
5018 If set, Bash expands occurrences of '&' in the replacement
5019 string of pattern substitution to the text matched by the
5020 pattern, as described above (*note Shell Parameter
5021 Expansion::). This option is enabled by default.
5022
5023 'progcomp'
5024 If set, the programmable completion facilities (*note
5025 Programmable Completion::) are enabled. This option is
5026 enabled by default.
5027
5028 'progcomp_alias'
5029 If set, and programmable completion is enabled, Bash treats a
5030 command name that doesn't have any completions as a possible
5031 alias and attempts alias expansion. If it has an alias, Bash
5032 attempts programmable completion using the command word
5033 resulting from the expanded alias.
5034
5035 'promptvars'
5036 If set, prompt strings undergo parameter expansion, command
5037 substitution, arithmetic expansion, and quote removal after
5038 being expanded as described below (*note Controlling the
5039 Prompt::). This option is enabled by default.
5040
5041 'restricted_shell'
5042 The shell sets this option if it is started in restricted mode
5043 (*note The Restricted Shell::). The value may not be changed.
5044 This is not reset when the startup files are executed,
5045 allowing the startup files to discover whether or not a shell
5046 is restricted.
5047
5048 'shift_verbose'
5049 If this is set, the 'shift' builtin prints an error message
5050 when the shift count exceeds the number of positional
5051 parameters.
5052
5053 'sourcepath'
5054 If set, the '.' ('source') builtin uses the value of 'PATH' to
5055 find the directory containing the file supplied as an
5056 argument. This option is enabled by default.
5057
5058 'varredir_close'
5059 If set, the shell automatically closes file descriptors
5060 assigned using the '{varname}' redirection syntax (*note
5061 Redirections::) instead of leaving them open when the command
5062 completes.
5063
5064 'xpg_echo'
5065 If set, the 'echo' builtin expands backslash-escape sequences
5066 by default.
5067
5068\1f
5069File: bashref.info, Node: Special Builtins, Prev: Modifying Shell Behavior, Up: Shell Builtin Commands
5070
50714.4 Special Builtins
5072====================
5073
5074For historical reasons, the POSIX standard has classified several
5075builtin commands as _special_. When Bash is executing in POSIX mode,
5076the special builtins differ from other builtin commands in three
5077respects:
5078
5079 1. Special builtins are found before shell functions during command
5080 lookup.
5081
5082 2. If a special builtin returns an error status, a non-interactive
5083 shell exits.
5084
5085 3. Assignment statements preceding the command stay in effect in the
5086 shell environment after the command completes.
5087
5088 When Bash is not executing in POSIX mode, these builtins behave no
5089differently than the rest of the Bash builtin commands. The Bash POSIX
5090mode is described in *note Bash POSIX Mode::.
5091
5092 These are the POSIX special builtins:
5093 break : . continue eval exec exit export readonly return set
5094 shift trap unset
5095
5096\1f
5097File: bashref.info, Node: Shell Variables, Next: Bash Features, Prev: Shell Builtin Commands, Up: Top
5098
50995 Shell Variables
5100*****************
5101
5102* Menu:
5103
5104* Bourne Shell Variables:: Variables which Bash uses in the same way
5105 as the Bourne Shell.
5106* Bash Variables:: List of variables that exist in Bash.
5107
5108This chapter describes the shell variables that Bash uses. Bash
5109automatically assigns default values to a number of variables.
5110
5111\1f
5112File: bashref.info, Node: Bourne Shell Variables, Next: Bash Variables, Up: Shell Variables
5113
51145.1 Bourne Shell Variables
5115==========================
5116
5117Bash uses certain shell variables in the same way as the Bourne shell.
5118In some cases, Bash assigns a default value to the variable.
5119
5120'CDPATH'
5121 A colon-separated list of directories used as a search path for the
5122 'cd' builtin command.
5123
5124'HOME'
5125 The current user's home directory; the default for the 'cd' builtin
5126 command. The value of this variable is also used by tilde
5127 expansion (*note Tilde Expansion::).
5128
5129'IFS'
5130 A list of characters that separate fields; used when the shell
5131 splits words as part of expansion.
5132
5133'MAIL'
5134 If this parameter is set to a filename or directory name and the
5135 'MAILPATH' variable is not set, Bash informs the user of the
5136 arrival of mail in the specified file or Maildir-format directory.
5137
5138'MAILPATH'
5139 A colon-separated list of filenames which the shell periodically
5140 checks for new mail. Each list entry can specify the message that
5141 is printed when new mail arrives in the mail file by separating the
5142 filename from the message with a '?'. When used in the text of the
5143 message, '$_' expands to the name of the current mail file.
5144
5145'OPTARG'
5146 The value of the last option argument processed by the 'getopts'
5147 builtin.
5148
5149'OPTIND'
5150 The index of the last option argument processed by the 'getopts'
5151 builtin.
5152
5153'PATH'
5154 A colon-separated list of directories in which the shell looks for
5155 commands. A zero-length (null) directory name in the value of
5156 'PATH' indicates the current directory. A null directory name may
5157 appear as two adjacent colons, or as an initial or trailing colon.
5158
5159'PS1'
5160 The primary prompt string. The default value is '\s-\v\$ '. *Note
5161 Controlling the Prompt::, for the complete list of escape sequences
5162 that are expanded before 'PS1' is displayed.
5163
5164'PS2'
5165 The secondary prompt string. The default value is '> '. 'PS2' is
5166 expanded in the same way as 'PS1' before being displayed.
5167
5168\1f
5169File: bashref.info, Node: Bash Variables, Prev: Bourne Shell Variables, Up: Shell Variables
5170
51715.2 Bash Variables
5172==================
5173
5174These variables are set or used by Bash, but other shells do not
5175normally treat them specially.
5176
5177 A few variables used by Bash are described in different chapters:
5178variables for controlling the job control facilities (*note Job Control
5179Variables::).
5180
5181'_'
5182 ($_, an underscore.) At shell startup, set to the pathname used to
5183 invoke the shell or shell script being executed as passed in the
5184 environment or argument list. Subsequently, expands to the last
5185 argument to the previous simple command executed in the foreground,
5186 after expansion. Also set to the full pathname used to invoke each
5187 command executed and placed in the environment exported to that
5188 command. When checking mail, this parameter holds the name of the
5189 mail file.
5190
5191'BASH'
5192 The full pathname used to execute the current instance of Bash.
5193
5194'BASHOPTS'
5195 A colon-separated list of enabled shell options. Each word in the
5196 list is a valid argument for the '-s' option to the 'shopt' builtin
5197 command (*note The Shopt Builtin::). The options appearing in
5198 'BASHOPTS' are those reported as 'on' by 'shopt'. If this variable
5199 is in the environment when Bash starts up, each shell option in the
5200 list will be enabled before reading any startup files. This
5201 variable is readonly.
5202
5203'BASHPID'
5204 Expands to the process ID of the current Bash process. This
5205 differs from '$$' under certain circumstances, such as subshells
5206 that do not require Bash to be re-initialized. Assignments to
5207 'BASHPID' have no effect. If 'BASHPID' is unset, it loses its
5208 special properties, even if it is subsequently reset.
5209
5210'BASH_ALIASES'
5211 An associative array variable whose members correspond to the
5212 internal list of aliases as maintained by the 'alias' builtin.
5213 (*note Bourne Shell Builtins::). Elements added to this array
5214 appear in the alias list; however, unsetting array elements
5215 currently does not cause aliases to be removed from the alias list.
5216 If 'BASH_ALIASES' is unset, it loses its special properties, even
5217 if it is subsequently reset.
5218
5219'BASH_ARGC'
5220 An array variable whose values are the number of parameters in each
5221 frame of the current bash execution call stack. The number of
5222 parameters to the current subroutine (shell function or script
5223 executed with '.' or 'source') is at the top of the stack. When a
5224 subroutine is executed, the number of parameters passed is pushed
5225 onto 'BASH_ARGC'. The shell sets 'BASH_ARGC' only when in extended
5226 debugging mode (see *note The Shopt Builtin:: for a description of
5227 the 'extdebug' option to the 'shopt' builtin). Setting 'extdebug'
5228 after the shell has started to execute a script, or referencing
5229 this variable when 'extdebug' is not set, may result in
5230 inconsistent values.
5231
5232'BASH_ARGV'
5233 An array variable containing all of the parameters in the current
5234 bash execution call stack. The final parameter of the last
5235 subroutine call is at the top of the stack; the first parameter of
5236 the initial call is at the bottom. When a subroutine is executed,
5237 the parameters supplied are pushed onto 'BASH_ARGV'. The shell
5238 sets 'BASH_ARGV' only when in extended debugging mode (see *note
5239 The Shopt Builtin:: for a description of the 'extdebug' option to
5240 the 'shopt' builtin). Setting 'extdebug' after the shell has
5241 started to execute a script, or referencing this variable when
5242 'extdebug' is not set, may result in inconsistent values.
5243
5244'BASH_ARGV0'
5245 When referenced, this variable expands to the name of the shell or
5246 shell script (identical to '$0'; *Note Special Parameters::, for
5247 the description of special parameter 0). Assignment to
5248 'BASH_ARGV0' causes the value assigned to also be assigned to '$0'.
5249 If 'BASH_ARGV0' is unset, it loses its special properties, even if
5250 it is subsequently reset.
5251
5252'BASH_CMDS'
5253 An associative array variable whose members correspond to the
5254 internal hash table of commands as maintained by the 'hash' builtin
5255 (*note Bourne Shell Builtins::). Elements added to this array
5256 appear in the hash table; however, unsetting array elements
5257 currently does not cause command names to be removed from the hash
5258 table. If 'BASH_CMDS' is unset, it loses its special properties,
5259 even if it is subsequently reset.
5260
5261'BASH_COMMAND'
5262 The command currently being executed or about to be executed,
5263 unless the shell is executing a command as the result of a trap, in
5264 which case it is the command executing at the time of the trap. If
5265 'BASH_COMMAND' is unset, it loses its special properties, even if
5266 it is subsequently reset.
5267
5268'BASH_COMPAT'
5269 The value is used to set the shell's compatibility level. *Note
5270 Shell Compatibility Mode::, for a description of the various
5271 compatibility levels and their effects. The value may be a decimal
5272 number (e.g., 4.2) or an integer (e.g., 42) corresponding to the
5273 desired compatibility level. If 'BASH_COMPAT' is unset or set to
5274 the empty string, the compatibility level is set to the default for
5275 the current version. If 'BASH_COMPAT' is set to a value that is
5276 not one of the valid compatibility levels, the shell prints an
5277 error message and sets the compatibility level to the default for
5278 the current version. The valid values correspond to the
5279 compatibility levels described below (*note Shell Compatibility
5280 Mode::). For example, 4.2 and 42 are valid values that correspond
5281 to the 'compat42' 'shopt' option and set the compatibility level to
5282 42. The current version is also a valid value.
5283
5284'BASH_ENV'
5285 If this variable is set when Bash is invoked to execute a shell
5286 script, its value is expanded and used as the name of a startup
5287 file to read before executing the script. *Note Bash Startup
5288 Files::.
5289
5290'BASH_EXECUTION_STRING'
5291 The command argument to the '-c' invocation option.
5292
5293'BASH_LINENO'
5294 An array variable whose members are the line numbers in source
5295 files where each corresponding member of 'FUNCNAME' was invoked.
5296 '${BASH_LINENO[$i]}' is the line number in the source file
5297 ('${BASH_SOURCE[$i+1]}') where '${FUNCNAME[$i]}' was called (or
5298 '${BASH_LINENO[$i-1]}' if referenced within another shell
5299 function). Use 'LINENO' to obtain the current line number.
5300
5301'BASH_LOADABLES_PATH'
5302 A colon-separated list of directories in which the shell looks for
5303 dynamically loadable builtins specified by the 'enable' command.
5304
5305'BASH_REMATCH'
5306 An array variable whose members are assigned by the '=~' binary
5307 operator to the '[[' conditional command (*note Conditional
5308 Constructs::). The element with index 0 is the portion of the
5309 string matching the entire regular expression. The element with
5310 index N is the portion of the string matching the Nth parenthesized
5311 subexpression.
5312
5313'BASH_SOURCE'
5314 An array variable whose members are the source filenames where the
5315 corresponding shell function names in the 'FUNCNAME' array variable
5316 are defined. The shell function '${FUNCNAME[$i]}' is defined in
5317 the file '${BASH_SOURCE[$i]}' and called from
5318 '${BASH_SOURCE[$i+1]}'
5319
5320'BASH_SUBSHELL'
5321 Incremented by one within each subshell or subshell environment
5322 when the shell begins executing in that environment. The initial
5323 value is 0. If 'BASH_SUBSHELL' is unset, it loses its special
5324 properties, even if it is subsequently reset.
5325
5326'BASH_VERSINFO'
5327 A readonly array variable (*note Arrays::) whose members hold
5328 version information for this instance of Bash. The values assigned
5329 to the array members are as follows:
5330
5331 'BASH_VERSINFO[0]'
5332 The major version number (the "release").
5333
5334 'BASH_VERSINFO[1]'
5335 The minor version number (the "version").
5336
5337 'BASH_VERSINFO[2]'
5338 The patch level.
5339
5340 'BASH_VERSINFO[3]'
5341 The build version.
5342
5343 'BASH_VERSINFO[4]'
5344 The release status (e.g., 'beta1').
5345
5346 'BASH_VERSINFO[5]'
5347 The value of 'MACHTYPE'.
5348
5349'BASH_VERSION'
5350 The version number of the current instance of Bash.
5351
5352'BASH_XTRACEFD'
5353 If set to an integer corresponding to a valid file descriptor, Bash
5354 will write the trace output generated when 'set -x' is enabled to
5355 that file descriptor. This allows tracing output to be separated
5356 from diagnostic and error messages. The file descriptor is closed
5357 when 'BASH_XTRACEFD' is unset or assigned a new value. Unsetting
5358 'BASH_XTRACEFD' or assigning it the empty string causes the trace
5359 output to be sent to the standard error. Note that setting
5360 'BASH_XTRACEFD' to 2 (the standard error file descriptor) and then
5361 unsetting it will result in the standard error being closed.
5362
5363'CHILD_MAX'
5364 Set the number of exited child status values for the shell to
5365 remember. Bash will not allow this value to be decreased below a
5366 POSIX-mandated minimum, and there is a maximum value (currently
5367 8192) that this may not exceed. The minimum value is
5368 system-dependent.
5369
5370'COLUMNS'
5371 Used by the 'select' command to determine the terminal width when
5372 printing selection lists. Automatically set if the 'checkwinsize'
5373 option is enabled (*note The Shopt Builtin::), or in an interactive
5374 shell upon receipt of a 'SIGWINCH'.
5375
5376'COMP_CWORD'
5377 An index into '${COMP_WORDS}' of the word containing the current
5378 cursor position. This variable is available only in shell
5379 functions invoked by the programmable completion facilities (*note
5380 Programmable Completion::).
5381
5382'COMP_LINE'
5383 The current command line. This variable is available only in shell
5384 functions and external commands invoked by the programmable
5385 completion facilities (*note Programmable Completion::).
5386
5387'COMP_POINT'
5388 The index of the current cursor position relative to the beginning
5389 of the current command. If the current cursor position is at the
5390 end of the current command, the value of this variable is equal to
5391 '${#COMP_LINE}'. This variable is available only in shell
5392 functions and external commands invoked by the programmable
5393 completion facilities (*note Programmable Completion::).
5394
5395'COMP_TYPE'
5396 Set to an integer value corresponding to the type of completion
5397 attempted that caused a completion function to be called: <TAB>,
5398 for normal completion, '?', for listing completions after
5399 successive tabs, '!', for listing alternatives on partial word
5400 completion, '@', to list completions if the word is not unmodified,
5401 or '%', for menu completion. This variable is available only in
5402 shell functions and external commands invoked by the programmable
5403 completion facilities (*note Programmable Completion::).
5404
5405'COMP_KEY'
5406 The key (or final key of a key sequence) used to invoke the current
5407 completion function.
5408
5409'COMP_WORDBREAKS'
5410 The set of characters that the Readline library treats as word
5411 separators when performing word completion. If 'COMP_WORDBREAKS'
5412 is unset, it loses its special properties, even if it is
5413 subsequently reset.
5414
5415'COMP_WORDS'
5416 An array variable consisting of the individual words in the current
5417 command line. The line is split into words as Readline would split
5418 it, using 'COMP_WORDBREAKS' as described above. This variable is
5419 available only in shell functions invoked by the programmable
5420 completion facilities (*note Programmable Completion::).
5421
5422'COMPREPLY'
5423 An array variable from which Bash reads the possible completions
5424 generated by a shell function invoked by the programmable
5425 completion facility (*note Programmable Completion::). Each array
5426 element contains one possible completion.
5427
5428'COPROC'
5429 An array variable created to hold the file descriptors for output
5430 from and input to an unnamed coprocess (*note Coprocesses::).
5431
5432'DIRSTACK'
5433 An array variable containing the current contents of the directory
5434 stack. Directories appear in the stack in the order they are
5435 displayed by the 'dirs' builtin. Assigning to members of this
5436 array variable may be used to modify directories already in the
5437 stack, but the 'pushd' and 'popd' builtins must be used to add and
5438 remove directories. Assignment to this variable will not change
5439 the current directory. If 'DIRSTACK' is unset, it loses its
5440 special properties, even if it is subsequently reset.
5441
5442'EMACS'
5443 If Bash finds this variable in the environment when the shell
5444 starts with value 't', it assumes that the shell is running in an
5445 Emacs shell buffer and disables line editing.
5446
5447'ENV'
5448 Expanded and executed similarly to 'BASH_ENV' (*note Bash Startup
5449 Files::) when an interactive shell is invoked in POSIX Mode (*note
5450 Bash POSIX Mode::).
5451
5452'EPOCHREALTIME'
5453 Each time this parameter is referenced, it expands to the number of
5454 seconds since the Unix Epoch as a floating point value with
5455 micro-second granularity (see the documentation for the C library
5456 function 'time' for the definition of Epoch). Assignments to
5457 'EPOCHREALTIME' are ignored. If 'EPOCHREALTIME' is unset, it loses
5458 its special properties, even if it is subsequently reset.
5459
5460'EPOCHSECONDS'
5461 Each time this parameter is referenced, it expands to the number of
5462 seconds since the Unix Epoch (see the documentation for the C
5463 library function 'time' for the definition of Epoch). Assignments
5464 to 'EPOCHSECONDS' are ignored. If 'EPOCHSECONDS' is unset, it
5465 loses its special properties, even if it is subsequently reset.
5466
5467'EUID'
5468 The numeric effective user id of the current user. This variable
5469 is readonly.
5470
5471'EXECIGNORE'
5472 A colon-separated list of shell patterns (*note Pattern Matching::)
5473 defining the list of filenames to be ignored by command search
5474 using 'PATH'. Files whose full pathnames match one of these
5475 patterns are not considered executable files for the purposes of
5476 completion and command execution via 'PATH' lookup. This does not
5477 affect the behavior of the '[', 'test', and '[[' commands. Full
5478 pathnames in the command hash table are not subject to
5479 'EXECIGNORE'. Use this variable to ignore shared library files
5480 that have the executable bit set, but are not executable files.
5481 The pattern matching honors the setting of the 'extglob' shell
5482 option.
5483
5484'FCEDIT'
5485 The editor used as a default by the '-e' option to the 'fc' builtin
5486 command.
5487
5488'FIGNORE'
5489 A colon-separated list of suffixes to ignore when performing
5490 filename completion. A filename whose suffix matches one of the
5491 entries in 'FIGNORE' is excluded from the list of matched
5492 filenames. A sample value is '.o:~'
5493
5494'FUNCNAME'
5495 An array variable containing the names of all shell functions
5496 currently in the execution call stack. The element with index 0 is
5497 the name of any currently-executing shell function. The
5498 bottom-most element (the one with the highest index) is '"main"'.
5499 This variable exists only when a shell function is executing.
5500 Assignments to 'FUNCNAME' have no effect. If 'FUNCNAME' is unset,
5501 it loses its special properties, even if it is subsequently reset.
5502
5503 This variable can be used with 'BASH_LINENO' and 'BASH_SOURCE'.
5504 Each element of 'FUNCNAME' has corresponding elements in
5505 'BASH_LINENO' and 'BASH_SOURCE' to describe the call stack. For
5506 instance, '${FUNCNAME[$i]}' was called from the file
5507 '${BASH_SOURCE[$i+1]}' at line number '${BASH_LINENO[$i]}'. The
5508 'caller' builtin displays the current call stack using this
5509 information.
5510
5511'FUNCNEST'
5512 If set to a numeric value greater than 0, defines a maximum
5513 function nesting level. Function invocations that exceed this
5514 nesting level will cause the current command to abort.
5515
5516'GLOBIGNORE'
5517 A colon-separated list of patterns defining the set of file names
5518 to be ignored by filename expansion. If a file name matched by a
5519 filename expansion pattern also matches one of the patterns in
5520 'GLOBIGNORE', it is removed from the list of matches. The pattern
5521 matching honors the setting of the 'extglob' shell option.
5522
5523'GROUPS'
5524 An array variable containing the list of groups of which the
5525 current user is a member. Assignments to 'GROUPS' have no effect.
5526 If 'GROUPS' is unset, it loses its special properties, even if it
5527 is subsequently reset.
5528
5529'histchars'
5530 Up to three characters which control history expansion, quick
5531 substitution, and tokenization (*note History Interaction::). The
5532 first character is the "history expansion" character, that is, the
5533 character which signifies the start of a history expansion,
5534 normally '!'. The second character is the character which
5535 signifies 'quick substitution' when seen as the first character on
5536 a line, normally '^'. The optional third character is the
5537 character which indicates that the remainder of the line is a
5538 comment when found as the first character of a word, usually '#'.
5539 The history comment character causes history substitution to be
5540 skipped for the remaining words on the line. It does not
5541 necessarily cause the shell parser to treat the rest of the line as
5542 a comment.
5543
5544'HISTCMD'
5545 The history number, or index in the history list, of the current
5546 command. Assignments to 'HISTCMD' are ignored. If 'HISTCMD' is
5547 unset, it loses its special properties, even if it is subsequently
5548 reset.
5549
5550'HISTCONTROL'
5551 A colon-separated list of values controlling how commands are saved
5552 on the history list. If the list of values includes 'ignorespace',
5553 lines which begin with a space character are not saved in the
5554 history list. A value of 'ignoredups' causes lines which match the
5555 previous history entry to not be saved. A value of 'ignoreboth' is
5556 shorthand for 'ignorespace' and 'ignoredups'. A value of
5557 'erasedups' causes all previous lines matching the current line to
5558 be removed from the history list before that line is saved. Any
5559 value not in the above list is ignored. If 'HISTCONTROL' is unset,
5560 or does not include a valid value, all lines read by the shell
5561 parser are saved on the history list, subject to the value of
5562 'HISTIGNORE'. The second and subsequent lines of a multi-line
5563 compound command are not tested, and are added to the history
5564 regardless of the value of 'HISTCONTROL'.
5565
5566'HISTFILE'
5567 The name of the file to which the command history is saved. The
5568 default value is '~/.bash_history'.
5569
5570'HISTFILESIZE'
5571 The maximum number of lines contained in the history file. When
5572 this variable is assigned a value, the history file is truncated,
5573 if necessary, to contain no more than that number of lines by
5574 removing the oldest entries. The history file is also truncated to
5575 this size after writing it when a shell exits. If the value is 0,
5576 the history file is truncated to zero size. Non-numeric values and
5577 numeric values less than zero inhibit truncation. The shell sets
5578 the default value to the value of 'HISTSIZE' after reading any
5579 startup files.
5580
5581'HISTIGNORE'
5582 A colon-separated list of patterns used to decide which command
5583 lines should be saved on the history list. Each pattern is
5584 anchored at the beginning of the line and must match the complete
5585 line (no implicit '*' is appended). Each pattern is tested against
5586 the line after the checks specified by 'HISTCONTROL' are applied.
5587 In addition to the normal shell pattern matching characters, '&'
5588 matches the previous history line. '&' may be escaped using a
5589 backslash; the backslash is removed before attempting a match. The
5590 second and subsequent lines of a multi-line compound command are
5591 not tested, and are added to the history regardless of the value of
5592 'HISTIGNORE'. The pattern matching honors the setting of the
5593 'extglob' shell option.
5594
5595 'HISTIGNORE' subsumes the function of 'HISTCONTROL'. A pattern of
5596 '&' is identical to 'ignoredups', and a pattern of '[ ]*' is
5597 identical to 'ignorespace'. Combining these two patterns,
5598 separating them with a colon, provides the functionality of
5599 'ignoreboth'.
5600
5601'HISTSIZE'
5602 The maximum number of commands to remember on the history list. If
5603 the value is 0, commands are not saved in the history list.
5604 Numeric values less than zero result in every command being saved
5605 on the history list (there is no limit). The shell sets the
5606 default value to 500 after reading any startup files.
5607
5608'HISTTIMEFORMAT'
5609 If this variable is set and not null, its value is used as a format
5610 string for 'strftime' to print the time stamp associated with each
5611 history entry displayed by the 'history' builtin. If this variable
5612 is set, time stamps are written to the history file so they may be
5613 preserved across shell sessions. This uses the history comment
5614 character to distinguish timestamps from other history lines.
5615
5616'HOSTFILE'
5617 Contains the name of a file in the same format as '/etc/hosts' that
5618 should be read when the shell needs to complete a hostname. The
5619 list of possible hostname completions may be changed while the
5620 shell is running; the next time hostname completion is attempted
5621 after the value is changed, Bash adds the contents of the new file
5622 to the existing list. If 'HOSTFILE' is set, but has no value, or
5623 does not name a readable file, Bash attempts to read '/etc/hosts'
5624 to obtain the list of possible hostname completions. When
5625 'HOSTFILE' is unset, the hostname list is cleared.
5626
5627'HOSTNAME'
5628 The name of the current host.
5629
5630'HOSTTYPE'
5631 A string describing the machine Bash is running on.
5632
5633'IGNOREEOF'
5634 Controls the action of the shell on receipt of an 'EOF' character
5635 as the sole input. If set, the value denotes the number of
5636 consecutive 'EOF' characters that can be read as the first
5637 character on an input line before the shell will exit. If the
5638 variable exists but does not have a numeric value, or has no value,
5639 then the default is 10. If the variable does not exist, then 'EOF'
5640 signifies the end of input to the shell. This is only in effect
5641 for interactive shells.
5642
5643'INPUTRC'
5644 The name of the Readline initialization file, overriding the
5645 default of '~/.inputrc'.
5646
5647'INSIDE_EMACS'
5648 If Bash finds this variable in the environment when the shell
5649 starts, it assumes that the shell is running in an Emacs shell
5650 buffer and may disable line editing depending on the value of
5651 'TERM'.
5652
5653'LANG'
5654 Used to determine the locale category for any category not
5655 specifically selected with a variable starting with 'LC_'.
5656
5657'LC_ALL'
5658 This variable overrides the value of 'LANG' and any other 'LC_'
5659 variable specifying a locale category.
5660
5661'LC_COLLATE'
5662 This variable determines the collation order used when sorting the
5663 results of filename expansion, and determines the behavior of range
5664 expressions, equivalence classes, and collating sequences within
5665 filename expansion and pattern matching (*note Filename
5666 Expansion::).
5667
5668'LC_CTYPE'
5669 This variable determines the interpretation of characters and the
5670 behavior of character classes within filename expansion and pattern
5671 matching (*note Filename Expansion::).
5672
5673'LC_MESSAGES'
5674 This variable determines the locale used to translate double-quoted
5675 strings preceded by a '$' (*note Locale Translation::).
5676
5677'LC_NUMERIC'
5678 This variable determines the locale category used for number
5679 formatting.
5680
5681'LC_TIME'
5682 This variable determines the locale category used for data and time
5683 formatting.
5684
5685'LINENO'
5686 The line number in the script or shell function currently
5687 executing. If 'LINENO' is unset, it loses its special properties,
5688 even if it is subsequently reset.
5689
5690'LINES'
5691 Used by the 'select' command to determine the column length for
5692 printing selection lists. Automatically set if the 'checkwinsize'
5693 option is enabled (*note The Shopt Builtin::), or in an interactive
5694 shell upon receipt of a 'SIGWINCH'.
5695
5696'MACHTYPE'
5697 A string that fully describes the system type on which Bash is
5698 executing, in the standard GNU CPU-COMPANY-SYSTEM format.
5699
5700'MAILCHECK'
5701 How often (in seconds) that the shell should check for mail in the
5702 files specified in the 'MAILPATH' or 'MAIL' variables. The default
5703 is 60 seconds. When it is time to check for mail, the shell does
5704 so before displaying the primary prompt. If this variable is
5705 unset, or set to a value that is not a number greater than or equal
5706 to zero, the shell disables mail checking.
5707
5708'MAPFILE'
5709 An array variable created to hold the text read by the 'mapfile'
5710 builtin when no variable name is supplied.
5711
5712'OLDPWD'
5713 The previous working directory as set by the 'cd' builtin.
5714
5715'OPTERR'
5716 If set to the value 1, Bash displays error messages generated by
5717 the 'getopts' builtin command.
5718
5719'OSTYPE'
5720 A string describing the operating system Bash is running on.
5721
5722'PIPESTATUS'
5723 An array variable (*note Arrays::) containing a list of exit status
5724 values from the processes in the most-recently-executed foreground
5725 pipeline (which may contain only a single command).
5726
5727'POSIXLY_CORRECT'
5728 If this variable is in the environment when Bash starts, the shell
5729 enters POSIX mode (*note Bash POSIX Mode::) before reading the
5730 startup files, as if the '--posix' invocation option had been
5731 supplied. If it is set while the shell is running, Bash enables
5732 POSIX mode, as if the command
5733 set -o posix
5734 had been executed. When the shell enters POSIX mode, it sets this
5735 variable if it was not already set.
5736
5737'PPID'
5738 The process ID of the shell's parent process. This variable is
5739 readonly.
5740
5741'PROMPT_COMMAND'
5742 If this variable is set, and is an array, the value of each set
5743 element is interpreted as a command to execute before printing the
5744 primary prompt ('$PS1'). If this is set but not an array variable,
5745 its value is used as a command to execute instead.
5746
5747'PROMPT_DIRTRIM'
5748 If set to a number greater than zero, the value is used as the
5749 number of trailing directory components to retain when expanding
5750 the '\w' and '\W' prompt string escapes (*note Controlling the
5751 Prompt::). Characters removed are replaced with an ellipsis.
5752
5753'PS0'
5754 The value of this parameter is expanded like 'PS1' and displayed by
5755 interactive shells after reading a command and before the command
5756 is executed.
5757
5758'PS3'
5759 The value of this variable is used as the prompt for the 'select'
5760 command. If this variable is not set, the 'select' command prompts
5761 with '#? '
5762
5763'PS4'
5764 The value of this parameter is expanded like 'PS1' and the expanded
5765 value is the prompt printed before the command line is echoed when
5766 the '-x' option is set (*note The Set Builtin::). The first
5767 character of the expanded value is replicated multiple times, as
5768 necessary, to indicate multiple levels of indirection. The default
5769 is '+ '.
5770
5771'PWD'
5772 The current working directory as set by the 'cd' builtin.
5773
5774'RANDOM'
5775 Each time this parameter is referenced, it expands to a random
5776 integer between 0 and 32767. Assigning a value to this variable
5777 seeds the random number generator. If 'RANDOM' is unset, it loses
5778 its special properties, even if it is subsequently reset.
5779
5780'READLINE_ARGUMENT'
5781 Any numeric argument given to a Readline command that was defined
5782 using 'bind -x' (*note Bash Builtins:: when it was invoked.
5783
5784'READLINE_LINE'
5785 The contents of the Readline line buffer, for use with 'bind -x'
5786 (*note Bash Builtins::).
5787
5788'READLINE_MARK'
5789 The position of the "mark" (saved insertion point) in the Readline
5790 line buffer, for use with 'bind -x' (*note Bash Builtins::). The
5791 characters between the insertion point and the mark are often
5792 called the "region".
5793
5794'READLINE_POINT'
5795 The position of the insertion point in the Readline line buffer,
5796 for use with 'bind -x' (*note Bash Builtins::).
5797
5798'REPLY'
5799 The default variable for the 'read' builtin.
5800
5801'SECONDS'
5802 This variable expands to the number of seconds since the shell was
5803 started. Assignment to this variable resets the count to the value
5804 assigned, and the expanded value becomes the value assigned plus
5805 the number of seconds since the assignment. The number of seconds
5806 at shell invocation and the current time are always determined by
5807 querying the system clock. If 'SECONDS' is unset, it loses its
5808 special properties, even if it is subsequently reset.
5809
5810'SHELL'
5811 This environment variable expands to the full pathname to the
5812 shell. If it is not set when the shell starts, Bash assigns to it
5813 the full pathname of the current user's login shell.
5814
5815'SHELLOPTS'
5816 A colon-separated list of enabled shell options. Each word in the
5817 list is a valid argument for the '-o' option to the 'set' builtin
5818 command (*note The Set Builtin::). The options appearing in
5819 'SHELLOPTS' are those reported as 'on' by 'set -o'. If this
5820 variable is in the environment when Bash starts up, each shell
5821 option in the list will be enabled before reading any startup
5822 files. This variable is readonly.
5823
5824'SHLVL'
5825 Incremented by one each time a new instance of Bash is started.
5826 This is intended to be a count of how deeply your Bash shells are
5827 nested.
5828
5829'SRANDOM'
5830 This variable expands to a 32-bit pseudo-random number each time it
5831 is referenced. The random number generator is not linear on
5832 systems that support '/dev/urandom' or 'arc4random', so each
5833 returned number has no relationship to the numbers preceding it.
5834 The random number generator cannot be seeded, so assignments to
5835 this variable have no effect. If 'SRANDOM' is unset, it loses its
5836 special properties, even if it is subsequently reset.
5837
5838'TIMEFORMAT'
5839 The value of this parameter is used as a format string specifying
5840 how the timing information for pipelines prefixed with the 'time'
5841 reserved word should be displayed. The '%' character introduces an
5842 escape sequence that is expanded to a time value or other
5843 information. The escape sequences and their meanings are as
5844 follows; the braces denote optional portions.
5845
5846 '%%'
5847 A literal '%'.
5848
5849 '%[P][l]R'
5850 The elapsed time in seconds.
5851
5852 '%[P][l]U'
5853 The number of CPU seconds spent in user mode.
5854
5855 '%[P][l]S'
5856 The number of CPU seconds spent in system mode.
5857
5858 '%P'
5859 The CPU percentage, computed as (%U + %S) / %R.
5860
5861 The optional P is a digit specifying the precision, the number of
5862 fractional digits after a decimal point. A value of 0 causes no
5863 decimal point or fraction to be output. At most three places after
5864 the decimal point may be specified; values of P greater than 3 are
5865 changed to 3. If P is not specified, the value 3 is used.
5866
5867 The optional 'l' specifies a longer format, including minutes, of
5868 the form MMmSS.FFs. The value of P determines whether or not the
5869 fraction is included.
5870
5871 If this variable is not set, Bash acts as if it had the value
5872 $'\nreal\t%3lR\nuser\t%3lU\nsys\t%3lS'
5873 If the value is null, no timing information is displayed. A
5874 trailing newline is added when the format string is displayed.
5875
5876'TMOUT'
5877 If set to a value greater than zero, 'TMOUT' is treated as the
5878 default timeout for the 'read' builtin (*note Bash Builtins::).
5879 The 'select' command (*note Conditional Constructs::) terminates if
5880 input does not arrive after 'TMOUT' seconds when input is coming
5881 from a terminal.
5882
5883 In an interactive shell, the value is interpreted as the number of
5884 seconds to wait for a line of input after issuing the primary
5885 prompt. Bash terminates after waiting for that number of seconds
5886 if a complete line of input does not arrive.
5887
5888'TMPDIR'
5889 If set, Bash uses its value as the name of a directory in which
5890 Bash creates temporary files for the shell's use.
5891
5892'UID'
5893 The numeric real user id of the current user. This variable is
5894 readonly.
5895
5896\1f
5897File: bashref.info, Node: Bash Features, Next: Job Control, Prev: Shell Variables, Up: Top
5898
58996 Bash Features
5900***************
5901
5902This chapter describes features unique to Bash.
5903
5904* Menu:
5905
5906* Invoking Bash:: Command line options that you can give
5907 to Bash.
5908* Bash Startup Files:: When and how Bash executes scripts.
5909* Interactive Shells:: What an interactive shell is.
5910* Bash Conditional Expressions:: Primitives used in composing expressions for
5911 the 'test' builtin.
5912* Shell Arithmetic:: Arithmetic on shell variables.
5913* Aliases:: Substituting one command for another.
5914* Arrays:: Array Variables.
5915* The Directory Stack:: History of visited directories.
5916* Controlling the Prompt:: Customizing the various prompt strings.
5917* The Restricted Shell:: A more controlled mode of shell execution.
5918* Bash POSIX Mode:: Making Bash behave more closely to what
5919 the POSIX standard specifies.
5920* Shell Compatibility Mode:: How Bash supports behavior that was present
5921 in earlier versions and has changed.
5922
5923\1f
5924File: bashref.info, Node: Invoking Bash, Next: Bash Startup Files, Up: Bash Features
5925
59266.1 Invoking Bash
5927=================
5928
5929 bash [long-opt] [-ir] [-abefhkmnptuvxdBCDHP] [-o OPTION]
5930 [-O SHOPT_OPTION] [ARGUMENT ...]
5931 bash [long-opt] [-abefhkmnptuvxdBCDHP] [-o OPTION]
5932 [-O SHOPT_OPTION] -c STRING [ARGUMENT ...]
5933 bash [long-opt] -s [-abefhkmnptuvxdBCDHP] [-o OPTION]
5934 [-O SHOPT_OPTION] [ARGUMENT ...]
5935
5936 All of the single-character options used with the 'set' builtin
5937(*note The Set Builtin::) can be used as options when the shell is
5938invoked. In addition, there are several multi-character options that
5939you can use. These options must appear on the command line before the
5940single-character options to be recognized.
5941
5942'--debugger'
5943 Arrange for the debugger profile to be executed before the shell
5944 starts. Turns on extended debugging mode (see *note The Shopt
5945 Builtin:: for a description of the 'extdebug' option to the 'shopt'
5946 builtin).
5947
5948'--dump-po-strings'
5949 A list of all double-quoted strings preceded by '$' is printed on
5950 the standard output in the GNU 'gettext' PO (portable object) file
5951 format. Equivalent to '-D' except for the output format.
5952
5953'--dump-strings'
5954 Equivalent to '-D'.
5955
5956'--help'
5957 Display a usage message on standard output and exit successfully.
5958
5959'--init-file FILENAME'
5960'--rcfile FILENAME'
5961 Execute commands from FILENAME (instead of '~/.bashrc') in an
5962 interactive shell.
5963
5964'--login'
5965 Equivalent to '-l'.
5966
5967'--noediting'
5968 Do not use the GNU Readline library (*note Command Line Editing::)
5969 to read command lines when the shell is interactive.
5970
5971'--noprofile'
5972 Don't load the system-wide startup file '/etc/profile' or any of
5973 the personal initialization files '~/.bash_profile',
5974 '~/.bash_login', or '~/.profile' when Bash is invoked as a login
5975 shell.
5976
5977'--norc'
5978 Don't read the '~/.bashrc' initialization file in an interactive
5979 shell. This is on by default if the shell is invoked as 'sh'.
5980
5981'--posix'
5982 Change the behavior of Bash where the default operation differs
5983 from the POSIX standard to match the standard. This is intended to
5984 make Bash behave as a strict superset of that standard. *Note Bash
5985 POSIX Mode::, for a description of the Bash POSIX mode.
5986
5987'--restricted'
5988 Make the shell a restricted shell (*note The Restricted Shell::).
5989
5990'--verbose'
5991 Equivalent to '-v'. Print shell input lines as they're read.
5992
5993'--version'
5994 Show version information for this instance of Bash on the standard
5995 output and exit successfully.
5996
5997 There are several single-character options that may be supplied at
5998invocation which are not available with the 'set' builtin.
5999
6000'-c'
6001 Read and execute commands from the first non-option argument
6002 COMMAND_STRING, then exit. If there are arguments after the
6003 COMMAND_STRING, the first argument is assigned to '$0' and any
6004 remaining arguments are assigned to the positional parameters. The
6005 assignment to '$0' sets the name of the shell, which is used in
6006 warning and error messages.
6007
6008'-i'
6009 Force the shell to run interactively. Interactive shells are
6010 described in *note Interactive Shells::.
6011
6012'-l'
6013 Make this shell act as if it had been directly invoked by login.
6014 When the shell is interactive, this is equivalent to starting a
6015 login shell with 'exec -l bash'. When the shell is not
6016 interactive, the login shell startup files will be executed. 'exec
6017 bash -l' or 'exec bash --login' will replace the current shell with
6018 a Bash login shell. *Note Bash Startup Files::, for a description
6019 of the special behavior of a login shell.
6020
6021'-r'
6022 Make the shell a restricted shell (*note The Restricted Shell::).
6023
6024'-s'
6025 If this option is present, or if no arguments remain after option
6026 processing, then commands are read from the standard input. This
6027 option allows the positional parameters to be set when invoking an
6028 interactive shell or when reading input through a pipe.
6029
6030'-D'
6031 A list of all double-quoted strings preceded by '$' is printed on
6032 the standard output. These are the strings that are subject to
6033 language translation when the current locale is not 'C' or 'POSIX'
6034 (*note Locale Translation::). This implies the '-n' option; no
6035 commands will be executed.
6036
6037'[-+]O [SHOPT_OPTION]'
6038 SHOPT_OPTION is one of the shell options accepted by the 'shopt'
6039 builtin (*note The Shopt Builtin::). If SHOPT_OPTION is present,
6040 '-O' sets the value of that option; '+O' unsets it. If
6041 SHOPT_OPTION is not supplied, the names and values of the shell
6042 options accepted by 'shopt' are printed on the standard output. If
6043 the invocation option is '+O', the output is displayed in a format
6044 that may be reused as input.
6045
6046'--'
6047 A '--' signals the end of options and disables further option
6048 processing. Any arguments after the '--' are treated as filenames
6049 and arguments.
6050
6051 A _login_ shell is one whose first character of argument zero is '-',
6052or one invoked with the '--login' option.
6053
6054 An _interactive_ shell is one started without non-option arguments,
6055unless '-s' is specified, without specifying the '-c' option, and whose
6056input and output are both connected to terminals (as determined by
6057'isatty(3)'), or one started with the '-i' option. *Note Interactive
6058Shells::, for more information.
6059
6060 If arguments remain after option processing, and neither the '-c' nor
6061the '-s' option has been supplied, the first argument is assumed to be
6062the name of a file containing shell commands (*note Shell Scripts::).
6063When Bash is invoked in this fashion, '$0' is set to the name of the
6064file, and the positional parameters are set to the remaining arguments.
6065Bash reads and executes commands from this file, then exits. Bash's
6066exit status is the exit status of the last command executed in the
6067script. If no commands are executed, the exit status is 0.
6068
6069\1f
6070File: bashref.info, Node: Bash Startup Files, Next: Interactive Shells, Prev: Invoking Bash, Up: Bash Features
6071
60726.2 Bash Startup Files
6073======================
6074
6075This section describes how Bash executes its startup files. If any of
6076the files exist but cannot be read, Bash reports an error. Tildes are
6077expanded in filenames as described above under Tilde Expansion (*note
6078Tilde Expansion::).
6079
6080 Interactive shells are described in *note Interactive Shells::.
6081
6082Invoked as an interactive login shell, or with '--login'
6083........................................................
6084
6085When Bash is invoked as an interactive login shell, or as a
6086non-interactive shell with the '--login' option, it first reads and
6087executes commands from the file '/etc/profile', if that file exists.
6088After reading that file, it looks for '~/.bash_profile',
6089'~/.bash_login', and '~/.profile', in that order, and reads and executes
6090commands from the first one that exists and is readable. The
6091'--noprofile' option may be used when the shell is started to inhibit
6092this behavior.
6093
6094 When an interactive login shell exits, or a non-interactive login
6095shell executes the 'exit' builtin command, Bash reads and executes
6096commands from the file '~/.bash_logout', if it exists.
6097
6098Invoked as an interactive non-login shell
6099.........................................
6100
6101When an interactive shell that is not a login shell is started, Bash
6102reads and executes commands from '~/.bashrc', if that file exists. This
6103may be inhibited by using the '--norc' option. The '--rcfile FILE'
6104option will force Bash to read and execute commands from FILE instead of
6105'~/.bashrc'.
6106
6107 So, typically, your '~/.bash_profile' contains the line
6108 if [ -f ~/.bashrc ]; then . ~/.bashrc; fi
6109after (or before) any login-specific initializations.
6110
6111Invoked non-interactively
6112.........................
6113
6114When Bash is started non-interactively, to run a shell script, for
6115example, it looks for the variable 'BASH_ENV' in the environment,
6116expands its value if it appears there, and uses the expanded value as
6117the name of a file to read and execute. Bash behaves as if the
6118following command were executed:
6119 if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
6120but the value of the 'PATH' variable is not used to search for the
6121filename.
6122
6123 As noted above, if a non-interactive shell is invoked with the
6124'--login' option, Bash attempts to read and execute commands from the
6125login shell startup files.
6126
6127Invoked with name 'sh'
6128......................
6129
6130If Bash is invoked with the name 'sh', it tries to mimic the startup
6131behavior of historical versions of 'sh' as closely as possible, while
6132conforming to the POSIX standard as well.
6133
6134 When invoked as an interactive login shell, or as a non-interactive
6135shell with the '--login' option, it first attempts to read and execute
6136commands from '/etc/profile' and '~/.profile', in that order. The
6137'--noprofile' option may be used to inhibit this behavior. When invoked
6138as an interactive shell with the name 'sh', Bash looks for the variable
6139'ENV', expands its value if it is defined, and uses the expanded value
6140as the name of a file to read and execute. Since a shell invoked as
6141'sh' does not attempt to read and execute commands from any other
6142startup files, the '--rcfile' option has no effect. A non-interactive
6143shell invoked with the name 'sh' does not attempt to read any other
6144startup files.
6145
6146 When invoked as 'sh', Bash enters POSIX mode after the startup files
6147are read.
6148
6149Invoked in POSIX mode
6150.....................
6151
6152When Bash is started in POSIX mode, as with the '--posix' command line
6153option, it follows the POSIX standard for startup files. In this mode,
6154interactive shells expand the 'ENV' variable and commands are read and
6155executed from the file whose name is the expanded value. No other
6156startup files are read.
6157
6158Invoked by remote shell daemon
6159..............................
6160
6161Bash attempts to determine when it is being run with its standard input
6162connected to a network connection, as when executed by the historical
6163remote shell daemon, usually 'rshd', or the secure shell daemon 'sshd'.
6164If Bash determines it is being run non-interactively in this fashion, it
6165reads and executes commands from '~/.bashrc', if that file exists and is
6166readable. It will not do this if invoked as 'sh'. The '--norc' option
6167may be used to inhibit this behavior, and the '--rcfile' option may be
6168used to force another file to be read, but neither 'rshd' nor 'sshd'
6169generally invoke the shell with those options or allow them to be
6170specified.
6171
6172Invoked with unequal effective and real UID/GIDs
6173................................................
6174
6175If Bash is started with the effective user (group) id not equal to the
6176real user (group) id, and the '-p' option is not supplied, no startup
6177files are read, shell functions are not inherited from the environment,
6178the 'SHELLOPTS', 'BASHOPTS', 'CDPATH', and 'GLOBIGNORE' variables, if
6179they appear in the environment, are ignored, and the effective user id
6180is set to the real user id. If the '-p' option is supplied at
6181invocation, the startup behavior is the same, but the effective user id
6182is not reset.
6183
6184\1f
6185File: bashref.info, Node: Interactive Shells, Next: Bash Conditional Expressions, Prev: Bash Startup Files, Up: Bash Features
6186
61876.3 Interactive Shells
6188======================
6189
6190* Menu:
6191
6192* What is an Interactive Shell?:: What determines whether a shell is Interactive.
6193* Is this Shell Interactive?:: How to tell if a shell is interactive.
6194* Interactive Shell Behavior:: What changes in an interactive shell?
6195
6196\1f
6197File: bashref.info, Node: What is an Interactive Shell?, Next: Is this Shell Interactive?, Up: Interactive Shells
6198
61996.3.1 What is an Interactive Shell?
6200-----------------------------------
6201
6202An interactive shell is one started without non-option arguments (unless
6203'-s' is specified) and without specifying the '-c' option, whose input
6204and error output are both connected to terminals (as determined by
6205'isatty(3)'), or one started with the '-i' option.
6206
6207 An interactive shell generally reads from and writes to a user's
6208terminal.
6209
6210 The '-s' invocation option may be used to set the positional
6211parameters when an interactive shell is started.
6212
6213\1f
6214File: bashref.info, Node: Is this Shell Interactive?, Next: Interactive Shell Behavior, Prev: What is an Interactive Shell?, Up: Interactive Shells
6215
62166.3.2 Is this Shell Interactive?
6217--------------------------------
6218
6219To determine within a startup script whether or not Bash is running
6220interactively, test the value of the '-' special parameter. It contains
6221'i' when the shell is interactive. For example:
6222
6223 case "$-" in
6224 *i*) echo This shell is interactive ;;
6225 *) echo This shell is not interactive ;;
6226 esac
6227
6228 Alternatively, startup scripts may examine the variable 'PS1'; it is
6229unset in non-interactive shells, and set in interactive shells. Thus:
6230
6231 if [ -z "$PS1" ]; then
6232 echo This shell is not interactive
6233 else
6234 echo This shell is interactive
6235 fi
6236
6237\1f
6238File: bashref.info, Node: Interactive Shell Behavior, Prev: Is this Shell Interactive?, Up: Interactive Shells
6239
62406.3.3 Interactive Shell Behavior
6241--------------------------------
6242
6243When the shell is running interactively, it changes its behavior in
6244several ways.
6245
6246 1. Startup files are read and executed as described in *note Bash
6247 Startup Files::.
6248
6249 2. Job Control (*note Job Control::) is enabled by default. When job
6250 control is in effect, Bash ignores the keyboard-generated job
6251 control signals 'SIGTTIN', 'SIGTTOU', and 'SIGTSTP'.
6252
6253 3. Bash expands and displays 'PS1' before reading the first line of a
6254 command, and expands and displays 'PS2' before reading the second
6255 and subsequent lines of a multi-line command. Bash expands and
6256 displays 'PS0' after it reads a command but before executing it.
6257 See *note Controlling the Prompt::, for a complete list of prompt
6258 string escape sequences.
6259
6260 4. Bash executes the values of the set elements of the
6261 'PROMPT_COMMAND' array variable as commands before printing the
6262 primary prompt, '$PS1' (*note Bash Variables::).
6263
6264 5. Readline (*note Command Line Editing::) is used to read commands
6265 from the user's terminal.
6266
6267 6. Bash inspects the value of the 'ignoreeof' option to 'set -o'
6268 instead of exiting immediately when it receives an 'EOF' on its
6269 standard input when reading a command (*note The Set Builtin::).
6270
6271 7. Command history (*note Bash History Facilities::) and history
6272 expansion (*note History Interaction::) are enabled by default.
6273 Bash will save the command history to the file named by '$HISTFILE'
6274 when a shell with history enabled exits.
6275
6276 8. Alias expansion (*note Aliases::) is performed by default.
6277
6278 9. In the absence of any traps, Bash ignores 'SIGTERM' (*note
6279 Signals::).
6280
6281 10. In the absence of any traps, 'SIGINT' is caught and handled (*note
6282 Signals::). 'SIGINT' will interrupt some shell builtins.
6283
6284 11. An interactive login shell sends a 'SIGHUP' to all jobs on exit if
6285 the 'huponexit' shell option has been enabled (*note Signals::).
6286
6287 12. The '-n' invocation option is ignored, and 'set -n' has no effect
6288 (*note The Set Builtin::).
6289
6290 13. Bash will check for mail periodically, depending on the values of
6291 the 'MAIL', 'MAILPATH', and 'MAILCHECK' shell variables (*note Bash
6292 Variables::).
6293
6294 14. Expansion errors due to references to unbound shell variables
6295 after 'set -u' has been enabled will not cause the shell to exit
6296 (*note The Set Builtin::).
6297
6298 15. The shell will not exit on expansion errors caused by VAR being
6299 unset or null in '${VAR:?WORD}' expansions (*note Shell Parameter
6300 Expansion::).
6301
6302 16. Redirection errors encountered by shell builtins will not cause
6303 the shell to exit.
6304
6305 17. When running in POSIX mode, a special builtin returning an error
6306 status will not cause the shell to exit (*note Bash POSIX Mode::).
6307
6308 18. A failed 'exec' will not cause the shell to exit (*note Bourne
6309 Shell Builtins::).
6310
6311 19. Parser syntax errors will not cause the shell to exit.
6312
6313 20. If the 'cdspell' shell option is enabled, the shell will attempt
6314 simple spelling correction for directory arguments to the 'cd'
6315 builtin (see the description of the 'cdspell' option to the 'shopt'
6316 builtin in *note The Shopt Builtin::). The 'cdspell' option is
6317 only effective in interactive shells.
6318
6319 21. The shell will check the value of the 'TMOUT' variable and exit if
6320 a command is not read within the specified number of seconds after
6321 printing '$PS1' (*note Bash Variables::).
6322
6323\1f
6324File: bashref.info, Node: Bash Conditional Expressions, Next: Shell Arithmetic, Prev: Interactive Shells, Up: Bash Features
6325
63266.4 Bash Conditional Expressions
6327================================
6328
6329Conditional expressions are used by the '[[' compound command (*note
6330Conditional Constructs::) and the 'test' and '[' builtin commands (*note
6331Bourne Shell Builtins::). The 'test' and '[' commands determine their
6332behavior based on the number of arguments; see the descriptions of those
6333commands for any other command-specific actions.
6334
6335 Expressions may be unary or binary, and are formed from the following
6336primaries. Unary expressions are often used to examine the status of a
6337file. There are string operators and numeric comparison operators as
6338well. Bash handles several filenames specially when they are used in
6339expressions. If the operating system on which Bash is running provides
6340these special files, Bash will use them; otherwise it will emulate them
6341internally with this behavior: If the FILE argument to one of the
6342primaries is of the form '/dev/fd/N', then file descriptor N is checked.
6343If the FILE argument to one of the primaries is one of '/dev/stdin',
6344'/dev/stdout', or '/dev/stderr', file descriptor 0, 1, or 2,
6345respectively, is checked.
6346
6347 When used with '[[', the '<' and '>' operators sort lexicographically
6348using the current locale. The 'test' command uses ASCII ordering.
6349
6350 Unless otherwise specified, primaries that operate on files follow
6351symbolic links and operate on the target of the link, rather than the
6352link itself.
6353
6354'-a FILE'
6355 True if FILE exists.
6356
6357'-b FILE'
6358 True if FILE exists and is a block special file.
6359
6360'-c FILE'
6361 True if FILE exists and is a character special file.
6362
6363'-d FILE'
6364 True if FILE exists and is a directory.
6365
6366'-e FILE'
6367 True if FILE exists.
6368
6369'-f FILE'
6370 True if FILE exists and is a regular file.
6371
6372'-g FILE'
6373 True if FILE exists and its set-group-id bit is set.
6374
6375'-h FILE'
6376 True if FILE exists and is a symbolic link.
6377
6378'-k FILE'
6379 True if FILE exists and its "sticky" bit is set.
6380
6381'-p FILE'
6382 True if FILE exists and is a named pipe (FIFO).
6383
6384'-r FILE'
6385 True if FILE exists and is readable.
6386
6387'-s FILE'
6388 True if FILE exists and has a size greater than zero.
6389
6390'-t FD'
6391 True if file descriptor FD is open and refers to a terminal.
6392
6393'-u FILE'
6394 True if FILE exists and its set-user-id bit is set.
6395
6396'-w FILE'
6397 True if FILE exists and is writable.
6398
6399'-x FILE'
6400 True if FILE exists and is executable.
6401
6402'-G FILE'
6403 True if FILE exists and is owned by the effective group id.
6404
6405'-L FILE'
6406 True if FILE exists and is a symbolic link.
6407
6408'-N FILE'
6409 True if FILE exists and has been modified since it was last read.
6410
6411'-O FILE'
6412 True if FILE exists and is owned by the effective user id.
6413
6414'-S FILE'
6415 True if FILE exists and is a socket.
6416
6417'FILE1 -ef FILE2'
6418 True if FILE1 and FILE2 refer to the same device and inode numbers.
6419
6420'FILE1 -nt FILE2'
6421 True if FILE1 is newer (according to modification date) than FILE2,
6422 or if FILE1 exists and FILE2 does not.
6423
6424'FILE1 -ot FILE2'
6425 True if FILE1 is older than FILE2, or if FILE2 exists and FILE1
6426 does not.
6427
6428'-o OPTNAME'
6429 True if the shell option OPTNAME is enabled. The list of options
6430 appears in the description of the '-o' option to the 'set' builtin
6431 (*note The Set Builtin::).
6432
6433'-v VARNAME'
6434 True if the shell variable VARNAME is set (has been assigned a
6435 value).
6436
6437'-R VARNAME'
6438 True if the shell variable VARNAME is set and is a name reference.
6439
6440'-z STRING'
6441 True if the length of STRING is zero.
6442
6443'-n STRING'
6444'STRING'
6445 True if the length of STRING is non-zero.
6446
6447'STRING1 == STRING2'
6448'STRING1 = STRING2'
6449 True if the strings are equal. When used with the '[[' command,
6450 this performs pattern matching as described above (*note
6451 Conditional Constructs::).
6452
6453 '=' should be used with the 'test' command for POSIX conformance.
6454
6455'STRING1 != STRING2'
6456 True if the strings are not equal.
6457
6458'STRING1 < STRING2'
6459 True if STRING1 sorts before STRING2 lexicographically.
6460
6461'STRING1 > STRING2'
6462 True if STRING1 sorts after STRING2 lexicographically.
6463
6464'ARG1 OP ARG2'
6465 'OP' is one of '-eq', '-ne', '-lt', '-le', '-gt', or '-ge'. These
6466 arithmetic binary operators return true if ARG1 is equal to, not
6467 equal to, less than, less than or equal to, greater than, or
6468 greater than or equal to ARG2, respectively. ARG1 and ARG2 may be
6469 positive or negative integers. When used with the '[[' command,
6470 ARG1 and ARG2 are evaluated as arithmetic expressions (*note Shell
6471 Arithmetic::).
6472
6473\1f
6474File: bashref.info, Node: Shell Arithmetic, Next: Aliases, Prev: Bash Conditional Expressions, Up: Bash Features
6475
64766.5 Shell Arithmetic
6477====================
6478
6479The shell allows arithmetic expressions to be evaluated, as one of the
6480shell expansions or by using the '((' compound command, the 'let'
6481builtin, or the '-i' option to the 'declare' builtin.
6482
6483 Evaluation is done in fixed-width integers with no check for
6484overflow, though division by 0 is trapped and flagged as an error. The
6485operators and their precedence, associativity, and values are the same
6486as in the C language. The following list of operators is grouped into
6487levels of equal-precedence operators. The levels are listed in order of
6488decreasing precedence.
6489
6490'ID++ ID--'
6491 variable post-increment and post-decrement
6492
6493'++ID --ID'
6494 variable pre-increment and pre-decrement
6495
6496'- +'
6497 unary minus and plus
6498
6499'! ~'
6500 logical and bitwise negation
6501
6502'**'
6503 exponentiation
6504
6505'* / %'
6506 multiplication, division, remainder
6507
6508'+ -'
6509 addition, subtraction
6510
6511'<< >>'
6512 left and right bitwise shifts
6513
6514'<= >= < >'
6515 comparison
6516
6517'== !='
6518 equality and inequality
6519
6520'&'
6521 bitwise AND
6522
6523'^'
6524 bitwise exclusive OR
6525
6526'|'
6527 bitwise OR
6528
6529'&&'
6530 logical AND
6531
6532'||'
6533 logical OR
6534
6535'expr ? expr : expr'
6536 conditional operator
6537
6538'= *= /= %= += -= <<= >>= &= ^= |='
6539 assignment
6540
6541'expr1 , expr2'
6542 comma
6543
6544 Shell variables are allowed as operands; parameter expansion is
6545performed before the expression is evaluated. Within an expression,
6546shell variables may also be referenced by name without using the
6547parameter expansion syntax. A shell variable that is null or unset
6548evaluates to 0 when referenced by name without using the parameter
6549expansion syntax. The value of a variable is evaluated as an arithmetic
6550expression when it is referenced, or when a variable which has been
6551given the 'integer' attribute using 'declare -i' is assigned a value. A
6552null value evaluates to 0. A shell variable need not have its 'integer'
6553attribute turned on to be used in an expression.
6554
6555 Integer constants follow the C language definition, without suffixes
6556or character constants. Constants with a leading 0 are interpreted as
6557octal numbers. A leading '0x' or '0X' denotes hexadecimal. Otherwise,
6558numbers take the form [BASE'#']N, where the optional BASE is a decimal
6559number between 2 and 64 representing the arithmetic base, and N is a
6560number in that base. If BASE'#' is omitted, then base 10 is used. When
6561specifying N, if a non-digit is required, the digits greater than 9 are
6562represented by the lowercase letters, the uppercase letters, '@', and
6563'_', in that order. If BASE is less than or equal to 36, lowercase and
6564uppercase letters may be used interchangeably to represent numbers
6565between 10 and 35.
6566
6567 Operators are evaluated in order of precedence. Sub-expressions in
6568parentheses are evaluated first and may override the precedence rules
6569above.
6570
6571\1f
6572File: bashref.info, Node: Aliases, Next: Arrays, Prev: Shell Arithmetic, Up: Bash Features
6573
65746.6 Aliases
6575===========
6576
6577"Aliases" allow a string to be substituted for a word when it is used as
6578the first word of a simple command. The shell maintains a list of
6579aliases that may be set and unset with the 'alias' and 'unalias' builtin
6580commands.
6581
6582 The first word of each simple command, if unquoted, is checked to see
6583if it has an alias. If so, that word is replaced by the text of the
6584alias. The characters '/', '$', '`', '=' and any of the shell
6585metacharacters or quoting characters listed above may not appear in an
6586alias name. The replacement text may contain any valid shell input,
6587including shell metacharacters. The first word of the replacement text
6588is tested for aliases, but a word that is identical to an alias being
6589expanded is not expanded a second time. This means that one may alias
6590'ls' to '"ls -F"', for instance, and Bash does not try to recursively
6591expand the replacement text. If the last character of the alias value
6592is a 'blank', then the next command word following the alias is also
6593checked for alias expansion.
6594
6595 Aliases are created and listed with the 'alias' command, and removed
6596with the 'unalias' command.
6597
6598 There is no mechanism for using arguments in the replacement text, as
6599in 'csh'. If arguments are needed, use a shell function (*note Shell
6600Functions::).
6601
6602 Aliases are not expanded when the shell is not interactive, unless
6603the 'expand_aliases' shell option is set using 'shopt' (*note The Shopt
6604Builtin::).
6605
6606 The rules concerning the definition and use of aliases are somewhat
6607confusing. Bash always reads at least one complete line of input, and
6608all lines that make up a compound command, before executing any of the
6609commands on that line or the compound command. Aliases are expanded
6610when a command is read, not when it is executed. Therefore, an alias
6611definition appearing on the same line as another command does not take
6612effect until the next line of input is read. The commands following the
6613alias definition on that line are not affected by the new alias. This
6614behavior is also an issue when functions are executed. Aliases are
6615expanded when a function definition is read, not when the function is
6616executed, because a function definition is itself a command. As a
6617consequence, aliases defined in a function are not available until after
6618that function is executed. To be safe, always put alias definitions on
6619a separate line, and do not use 'alias' in compound commands.
6620
6621 For almost every purpose, shell functions are preferred over aliases.
6622
6623\1f
6624File: bashref.info, Node: Arrays, Next: The Directory Stack, Prev: Aliases, Up: Bash Features
6625
66266.7 Arrays
6627==========
6628
6629Bash provides one-dimensional indexed and associative array variables.
6630Any variable may be used as an indexed array; the 'declare' builtin will
6631explicitly declare an array. There is no maximum limit on the size of
6632an array, nor any requirement that members be indexed or assigned
6633contiguously. Indexed arrays are referenced using integers (including
6634arithmetic expressions (*note Shell Arithmetic::)) and are zero-based;
6635associative arrays use arbitrary strings. Unless otherwise noted,
6636indexed array indices must be non-negative integers.
6637
6638 An indexed array is created automatically if any variable is assigned
6639to using the syntax
6640 NAME[SUBSCRIPT]=VALUE
6641
6642The SUBSCRIPT is treated as an arithmetic expression that must evaluate
6643to a number. To explicitly declare an array, use
6644 declare -a NAME
6645The syntax
6646 declare -a NAME[SUBSCRIPT]
6647is also accepted; the SUBSCRIPT is ignored.
6648
6649Associative arrays are created using
6650 declare -A NAME
6651
6652 Attributes may be specified for an array variable using the 'declare'
6653and 'readonly' builtins. Each attribute applies to all members of an
6654array.
6655
6656 Arrays are assigned to using compound assignments of the form
6657 NAME=(VALUE1 VALUE2 ... )
6658where each VALUE may be of the form '[SUBSCRIPT]='STRING. Indexed array
6659assignments do not require anything but STRING. When assigning to
6660indexed arrays, if the optional subscript is supplied, that index is
6661assigned to; otherwise the index of the element assigned is the last
6662index assigned to by the statement plus one. Indexing starts at zero.
6663
6664 Each VALUE in the list undergoes all the shell expansions described
6665above (*note Shell Expansions::).
6666
6667 When assigning to an associative array, the words in a compound
6668assignment may be either assignment statements, for which the subscript
6669is required, or a list of words that is interpreted as a sequence of
6670alternating keys and values: NAME=(KEY1 VALUE1 KEY2 VALUE2 ... ). These
6671are treated identically to NAME=( [KEY1]=VALUE1 [KEY2]=VALUE2 ... ).
6672The first word in the list determines how the remaining words are
6673interpreted; all assignments in a list must be of the same type. When
6674using key/value pairs, the keys may not be missing or empty; a final
6675missing value is treated like the empty string.
6676
6677 This syntax is also accepted by the 'declare' builtin. Individual
6678array elements may be assigned to using the 'NAME[SUBSCRIPT]=VALUE'
6679syntax introduced above.
6680
6681 When assigning to an indexed array, if NAME is subscripted by a
6682negative number, that number is interpreted as relative to one greater
6683than the maximum index of NAME, so negative indices count back from the
6684end of the array, and an index of -1 references the last element.
6685
6686 The '+=' operator will append to an array variable when assigning
6687using the compound assignment syntax; see *note Shell Parameters::
6688above.
6689
6690 Any element of an array may be referenced using '${NAME[SUBSCRIPT]}'.
6691The braces are required to avoid conflicts with the shell's filename
6692expansion operators. If the SUBSCRIPT is '@' or '*', the word expands
6693to all members of the array NAME. These subscripts differ only when the
6694word appears within double quotes. If the word is double-quoted,
6695'${NAME[*]}' expands to a single word with the value of each array
6696member separated by the first character of the 'IFS' variable, and
6697'${NAME[@]}' expands each element of NAME to a separate word. When
6698there are no array members, '${NAME[@]}' expands to nothing. If the
6699double-quoted expansion occurs within a word, the expansion of the first
6700parameter is joined with the beginning part of the original word, and
6701the expansion of the last parameter is joined with the last part of the
6702original word. This is analogous to the expansion of the special
6703parameters '@' and '*'. '${#NAME[SUBSCRIPT]}' expands to the length of
6704'${NAME[SUBSCRIPT]}'. If SUBSCRIPT is '@' or '*', the expansion is the
6705number of elements in the array. If the SUBSCRIPT used to reference an
6706element of an indexed array evaluates to a number less than zero, it is
6707interpreted as relative to one greater than the maximum index of the
6708array, so negative indices count back from the end of the array, and an
6709index of -1 refers to the last element.
6710
6711 Referencing an array variable without a subscript is equivalent to
6712referencing with a subscript of 0. Any reference to a variable using a
6713valid subscript is legal, and 'bash' will create an array if necessary.
6714
6715 An array variable is considered set if a subscript has been assigned
6716a value. The null string is a valid value.
6717
6718 It is possible to obtain the keys (indices) of an array as well as
6719the values. ${!NAME[@]} and ${!NAME[*]} expand to the indices assigned
6720in array variable NAME. The treatment when in double quotes is similar
6721to the expansion of the special parameters '@' and '*' within double
6722quotes.
6723
6724 The 'unset' builtin is used to destroy arrays. 'unset
6725NAME[SUBSCRIPT]' destroys the array element at index SUBSCRIPT.
6726Negative subscripts to indexed arrays are interpreted as described
6727above. Unsetting the last element of an array variable does not unset
6728the variable. 'unset NAME', where NAME is an array, removes the entire
6729array. 'unset NAME[SUBSCRIPT]' behaves differently depending on the
6730array type when given a subscript of '*' or '@'. When NAME is an
6731associative array, it removes the element with key '*' or '@'. If NAME
6732is an indexed array, 'unset' removes all of the elements, but does not
6733remove the array itself.
6734
6735 When using a variable name with a subscript as an argument to a
6736command, such as with 'unset', without using the word expansion syntax
6737described above, the argument is subject to the shell's filename
6738expansion. If filename expansion is not desired, the argument should be
6739quoted.
6740
6741 The 'declare', 'local', and 'readonly' builtins each accept a '-a'
6742option to specify an indexed array and a '-A' option to specify an
6743associative array. If both options are supplied, '-A' takes precedence.
6744The 'read' builtin accepts a '-a' option to assign a list of words read
6745from the standard input to an array, and can read values from the
6746standard input into individual array elements. The 'set' and 'declare'
6747builtins display array values in a way that allows them to be reused as
6748input.
6749
6750\1f
6751File: bashref.info, Node: The Directory Stack, Next: Controlling the Prompt, Prev: Arrays, Up: Bash Features
6752
67536.8 The Directory Stack
6754=======================
6755
6756* Menu:
6757
6758* Directory Stack Builtins:: Bash builtin commands to manipulate
6759 the directory stack.
6760
6761The directory stack is a list of recently-visited directories. The
6762'pushd' builtin adds directories to the stack as it changes the current
6763directory, and the 'popd' builtin removes specified directories from the
6764stack and changes the current directory to the directory removed. The
6765'dirs' builtin displays the contents of the directory stack. The
6766current directory is always the "top" of the directory stack.
6767
6768 The contents of the directory stack are also visible as the value of
6769the 'DIRSTACK' shell variable.
6770
6771\1f
6772File: bashref.info, Node: Directory Stack Builtins, Up: The Directory Stack
6773
67746.8.1 Directory Stack Builtins
6775------------------------------
6776
6777'dirs'
6778 dirs [-clpv] [+N | -N]
6779
6780 Display the list of currently remembered directories. Directories
6781 are added to the list with the 'pushd' command; the 'popd' command
6782 removes directories from the list. The current directory is always
6783 the first directory in the stack.
6784
6785 '-c'
6786 Clears the directory stack by deleting all of the elements.
6787 '-l'
6788 Produces a listing using full pathnames; the default listing
6789 format uses a tilde to denote the home directory.
6790 '-p'
6791 Causes 'dirs' to print the directory stack with one entry per
6792 line.
6793 '-v'
6794 Causes 'dirs' to print the directory stack with one entry per
6795 line, prefixing each entry with its index in the stack.
6796 '+N'
6797 Displays the Nth directory (counting from the left of the list
6798 printed by 'dirs' when invoked without options), starting with
6799 zero.
6800 '-N'
6801 Displays the Nth directory (counting from the right of the
6802 list printed by 'dirs' when invoked without options), starting
6803 with zero.
6804
6805'popd'
6806 popd [-n] [+N | -N]
6807
6808 Removes elements from the directory stack. The elements are
6809 numbered from 0 starting at the first directory listed by 'dirs';
6810 that is, 'popd' is equivalent to 'popd +0'.
6811
6812 When no arguments are given, 'popd' removes the top directory from
6813 the stack and changes to the new top directory.
6814
6815 Arguments, if supplied, have the following meanings:
6816
6817 '-n'
6818 Suppresses the normal change of directory when removing
6819 directories from the stack, so that only the stack is
6820 manipulated.
6821 '+N'
6822 Removes the Nth directory (counting from the left of the list
6823 printed by 'dirs'), starting with zero, from the stack.
6824 '-N'
6825 Removes the Nth directory (counting from the right of the list
6826 printed by 'dirs'), starting with zero, from the stack.
6827
6828 If the top element of the directory stack is modified, and the '-n'
6829 option was not supplied, 'popd' uses the 'cd' builtin to change to
6830 the directory at the top of the stack. If the 'cd' fails, 'popd'
6831 returns a non-zero value.
6832
6833 Otherwise, 'popd' returns an unsuccessful status if an invalid
6834 option is encountered, the directory stack is empty, or a
6835 non-existent directory stack entry is specified.
6836
6837 If the 'popd' command is successful, Bash runs 'dirs' to show the
6838 final contents of the directory stack, and the return status is 0.
6839
6840'pushd'
6841 pushd [-n] [+N | -N | DIR]
6842
6843 Adds a directory to the top of the directory stack, or rotates the
6844 stack, making the new top of the stack the current working
6845 directory. With no arguments, 'pushd' exchanges the top two
6846 elements of the directory stack.
6847
6848 Arguments, if supplied, have the following meanings:
6849
6850 '-n'
6851 Suppresses the normal change of directory when rotating or
6852 adding directories to the stack, so that only the stack is
6853 manipulated.
6854 '+N'
6855 Brings the Nth directory (counting from the left of the list
6856 printed by 'dirs', starting with zero) to the top of the list
6857 by rotating the stack.
6858 '-N'
6859 Brings the Nth directory (counting from the right of the list
6860 printed by 'dirs', starting with zero) to the top of the list
6861 by rotating the stack.
6862 'DIR'
6863 Makes DIR be the top of the stack.
6864
6865 After the stack has been modified, if the '-n' option was not
6866 supplied, 'pushd' uses the 'cd' builtin to change to the directory
6867 at the top of the stack. If the 'cd' fails, 'pushd' returns a
6868 non-zero value.
6869
6870 Otherwise, if no arguments are supplied, 'pushd' returns 0 unless
6871 the directory stack is empty. When rotating the directory stack,
6872 'pushd' returns 0 unless the directory stack is empty or a
6873 non-existent directory stack element is specified.
6874
6875 If the 'pushd' command is successful, Bash runs 'dirs' to show the
6876 final contents of the directory stack.
6877
6878\1f
6879File: bashref.info, Node: Controlling the Prompt, Next: The Restricted Shell, Prev: The Directory Stack, Up: Bash Features
6880
68816.9 Controlling the Prompt
6882==========================
6883
6884Bash examines the value of the array variable 'PROMPT_COMMAND' just
6885before printing each primary prompt. If any elements in
6886'PROMPT_COMMAND' are set and non-null, Bash executes each value, in
6887numeric order, just as if it had been typed on the command line.
6888
6889 In addition, the following table describes the special characters
6890which can appear in the prompt variables 'PS0', 'PS1', 'PS2', and 'PS4':
6891
6892'\a'
6893 A bell character.
6894'\d'
6895 The date, in "Weekday Month Date" format (e.g., "Tue May 26").
6896'\D{FORMAT}'
6897 The FORMAT is passed to 'strftime'(3) and the result is inserted
6898 into the prompt string; an empty FORMAT results in a
6899 locale-specific time representation. The braces are required.
6900'\e'
6901 An escape character.
6902'\h'
6903 The hostname, up to the first '.'.
6904'\H'
6905 The hostname.
6906'\j'
6907 The number of jobs currently managed by the shell.
6908'\l'
6909 The basename of the shell's terminal device name.
6910'\n'
6911 A newline.
6912'\r'
6913 A carriage return.
6914'\s'
6915 The name of the shell, the basename of '$0' (the portion following
6916 the final slash).
6917'\t'
6918 The time, in 24-hour HH:MM:SS format.
6919'\T'
6920 The time, in 12-hour HH:MM:SS format.
6921'\@'
6922 The time, in 12-hour am/pm format.
6923'\A'
6924 The time, in 24-hour HH:MM format.
6925'\u'
6926 The username of the current user.
6927'\v'
6928 The version of Bash (e.g., 2.00)
6929'\V'
6930 The release of Bash, version + patchlevel (e.g., 2.00.0)
6931'\w'
6932 The value of the 'PWD' shell variable ('$PWD'), with '$HOME'
6933 abbreviated with a tilde (uses the '$PROMPT_DIRTRIM' variable).
6934'\W'
6935 The basename of '$PWD', with '$HOME' abbreviated with a tilde.
6936'\!'
6937 The history number of this command.
6938'\#'
6939 The command number of this command.
6940'\$'
6941 If the effective uid is 0, '#', otherwise '$'.
6942'\NNN'
6943 The character whose ASCII code is the octal value NNN.
6944'\\'
6945 A backslash.
6946'\['
6947 Begin a sequence of non-printing characters. This could be used to
6948 embed a terminal control sequence into the prompt.
6949'\]'
6950 End a sequence of non-printing characters.
6951
6952 The command number and the history number are usually different: the
6953history number of a command is its position in the history list, which
6954may include commands restored from the history file (*note Bash History
6955Facilities::), while the command number is the position in the sequence
6956of commands executed during the current shell session.
6957
6958 After the string is decoded, it is expanded via parameter expansion,
6959command substitution, arithmetic expansion, and quote removal, subject
6960to the value of the 'promptvars' shell option (*note The Shopt
6961Builtin::). This can have unwanted side effects if escaped portions of
6962the string appear within command substitution or contain characters
6963special to word expansion.
6964
6965\1f
6966File: bashref.info, Node: The Restricted Shell, Next: Bash POSIX Mode, Prev: Controlling the Prompt, Up: Bash Features
6967
69686.10 The Restricted Shell
6969=========================
6970
6971If Bash is started with the name 'rbash', or the '--restricted' or '-r'
6972option is supplied at invocation, the shell becomes restricted. A
6973restricted shell is used to set up an environment more controlled than
6974the standard shell. A restricted shell behaves identically to 'bash'
6975with the exception that the following are disallowed or not performed:
6976
6977 * Changing directories with the 'cd' builtin.
6978 * Setting or unsetting the values of the 'SHELL', 'PATH', 'HISTFILE',
6979 'ENV', or 'BASH_ENV' variables.
6980 * Specifying command names containing slashes.
6981 * Specifying a filename containing a slash as an argument to the '.'
6982 builtin command.
6983 * Specifying a filename containing a slash as an argument to the
6984 'history' builtin command.
6985 * Specifying a filename containing a slash as an argument to the '-p'
6986 option to the 'hash' builtin command.
6987 * Importing function definitions from the shell environment at
6988 startup.
6989 * Parsing the value of 'SHELLOPTS' from the shell environment at
6990 startup.
6991 * Redirecting output using the '>', '>|', '<>', '>&', '&>', and '>>'
6992 redirection operators.
6993 * Using the 'exec' builtin to replace the shell with another command.
6994 * Adding or deleting builtin commands with the '-f' and '-d' options
6995 to the 'enable' builtin.
6996 * Using the 'enable' builtin command to enable disabled shell
6997 builtins.
6998 * Specifying the '-p' option to the 'command' builtin.
6999 * Turning off restricted mode with 'set +r' or 'shopt -u
7000 restricted_shell'.
7001
7002 These restrictions are enforced after any startup files are read.
7003
7004 When a command that is found to be a shell script is executed (*note
7005Shell Scripts::), 'rbash' turns off any restrictions in the shell
7006spawned to execute the script.
7007
7008 The restricted shell mode is only one component of a useful
7009restricted environment. It should be accompanied by setting 'PATH' to a
7010value that allows execution of only a few verified commands (commands
7011that allow shell escapes are particularly vulnerable), changing the
7012current directory to a non-writable directory other than '$HOME' after
7013login, not allowing the restricted shell to execute shell scripts, and
7014cleaning the environment of variables that cause some commands to modify
7015their behavior (e.g., 'VISUAL' or 'PAGER').
7016
7017 Modern systems provide more secure ways to implement a restricted
7018environment, such as 'jails', 'zones', or 'containers'.
7019
7020\1f
7021File: bashref.info, Node: Bash POSIX Mode, Next: Shell Compatibility Mode, Prev: The Restricted Shell, Up: Bash Features
7022
70236.11 Bash POSIX Mode
7024====================
7025
7026Starting Bash with the '--posix' command-line option or executing 'set
7027-o posix' while Bash is running will cause Bash to conform more closely
7028to the POSIX standard by changing the behavior to match that specified
7029by POSIX in areas where the Bash default differs.
7030
7031 When invoked as 'sh', Bash enters POSIX mode after reading the
7032startup files.
7033
7034 The following list is what's changed when 'POSIX mode' is in effect:
7035
7036 1. Bash ensures that the 'POSIXLY_CORRECT' variable is set.
7037
7038 2. When a command in the hash table no longer exists, Bash will
7039 re-search '$PATH' to find the new location. This is also available
7040 with 'shopt -s checkhash'.
7041
7042 3. Bash will not insert a command without the execute bit set into the
7043 command hash table, even if it returns it as a (last-ditch) result
7044 from a '$PATH' search.
7045
7046 4. The message printed by the job control code and builtins when a job
7047 exits with a non-zero status is 'Done(status)'.
7048
7049 5. The message printed by the job control code and builtins when a job
7050 is stopped is 'Stopped(SIGNAME)', where SIGNAME is, for example,
7051 'SIGTSTP'.
7052
7053 6. Alias expansion is always enabled, even in non-interactive shells.
7054
7055 7. Reserved words appearing in a context where reserved words are
7056 recognized do not undergo alias expansion.
7057
7058 8. Alias expansion is performed when initially parsing a command
7059 substitution. The default mode generally defers it, when enabled,
7060 until the command substitution is executed. This means that
7061 command substitution will not expand aliases that are defined after
7062 the command substitution is initially parsed (e.g., as part of a
7063 function definition).
7064
7065 9. The POSIX 'PS1' and 'PS2' expansions of '!' to the history number
7066 and '!!' to '!' are enabled, and parameter expansion is performed
7067 on the values of 'PS1' and 'PS2' regardless of the setting of the
7068 'promptvars' option.
7069
7070 10. The POSIX startup files are executed ('$ENV') rather than the
7071 normal Bash files.
7072
7073 11. Tilde expansion is only performed on assignments preceding a
7074 command name, rather than on all assignment statements on the line.
7075
7076 12. The default history file is '~/.sh_history' (this is the default
7077 value of '$HISTFILE').
7078
7079 13. Redirection operators do not perform filename expansion on the
7080 word in the redirection unless the shell is interactive.
7081
7082 14. Redirection operators do not perform word splitting on the word in
7083 the redirection.
7084
7085 15. Function names must be valid shell 'name's. That is, they may not
7086 contain characters other than letters, digits, and underscores, and
7087 may not start with a digit. Declaring a function with an invalid
7088 name causes a fatal syntax error in non-interactive shells.
7089
7090 16. Function names may not be the same as one of the POSIX special
7091 builtins.
7092
7093 17. POSIX special builtins are found before shell functions during
7094 command lookup.
7095
7096 18. When printing shell function definitions (e.g., by 'type'), Bash
7097 does not print the 'function' keyword.
7098
7099 19. Literal tildes that appear as the first character in elements of
7100 the 'PATH' variable are not expanded as described above under *note
7101 Tilde Expansion::.
7102
7103 20. The 'time' reserved word may be used by itself as a command. When
7104 used in this way, it displays timing statistics for the shell and
7105 its completed children. The 'TIMEFORMAT' variable controls the
7106 format of the timing information.
7107
7108 21. When parsing and expanding a ${...} expansion that appears within
7109 double quotes, single quotes are no longer special and cannot be
7110 used to quote a closing brace or other special character, unless
7111 the operator is one of those defined to perform pattern removal.
7112 In this case, they do not have to appear as matched pairs.
7113
7114 22. The parser does not recognize 'time' as a reserved word if the
7115 next token begins with a '-'.
7116
7117 23. The '!' character does not introduce history expansion within a
7118 double-quoted string, even if the 'histexpand' option is enabled.
7119
7120 24. If a POSIX special builtin returns an error status, a
7121 non-interactive shell exits. The fatal errors are those listed in
7122 the POSIX standard, and include things like passing incorrect
7123 options, redirection errors, variable assignment errors for
7124 assignments preceding the command name, and so on.
7125
7126 25. A non-interactive shell exits with an error status if a variable
7127 assignment error occurs when no command name follows the assignment
7128 statements. A variable assignment error occurs, for example, when
7129 trying to assign a value to a readonly variable.
7130
7131 26. A non-interactive shell exits with an error status if a variable
7132 assignment error occurs in an assignment statement preceding a
7133 special builtin, but not with any other simple command. For any
7134 other simple command, the shell aborts execution of that command,
7135 and execution continues at the top level ("the shell shall not
7136 perform any further processing of the command in which the error
7137 occurred").
7138
7139 27. A non-interactive shell exits with an error status if the
7140 iteration variable in a 'for' statement or the selection variable
7141 in a 'select' statement is a readonly variable.
7142
7143 28. Non-interactive shells exit if FILENAME in '.' FILENAME is not
7144 found.
7145
7146 29. Non-interactive shells exit if a syntax error in an arithmetic
7147 expansion results in an invalid expression.
7148
7149 30. Non-interactive shells exit if a parameter expansion error occurs.
7150
7151 31. Non-interactive shells exit if there is a syntax error in a script
7152 read with the '.' or 'source' builtins, or in a string processed by
7153 the 'eval' builtin.
7154
7155 32. While variable indirection is available, it may not be applied to
7156 the '#' and '?' special parameters.
7157
7158 33. Expanding the '*' special parameter in a pattern context where the
7159 expansion is double-quoted does not treat the '$*' as if it were
7160 double-quoted.
7161
7162 34. Assignment statements preceding POSIX special builtins persist in
7163 the shell environment after the builtin completes.
7164
7165 35. The 'command' builtin does not prevent builtins that take
7166 assignment statements as arguments from expanding them as
7167 assignment statements; when not in POSIX mode, assignment builtins
7168 lose their assignment statement expansion properties when preceded
7169 by 'command'.
7170
7171 36. The 'bg' builtin uses the required format to describe each job
7172 placed in the background, which does not include an indication of
7173 whether the job is the current or previous job.
7174
7175 37. The output of 'kill -l' prints all the signal names on a single
7176 line, separated by spaces, without the 'SIG' prefix.
7177
7178 38. The 'kill' builtin does not accept signal names with a 'SIG'
7179 prefix.
7180
7181 39. The 'export' and 'readonly' builtin commands display their output
7182 in the format required by POSIX.
7183
7184 40. The 'trap' builtin displays signal names without the leading
7185 'SIG'.
7186
7187 41. The 'trap' builtin doesn't check the first argument for a possible
7188 signal specification and revert the signal handling to the original
7189 disposition if it is, unless that argument consists solely of
7190 digits and is a valid signal number. If users want to reset the
7191 handler for a given signal to the original disposition, they should
7192 use '-' as the first argument.
7193
7194 42. 'trap -p' displays signals whose dispositions are set to SIG_DFL
7195 and those that were ignored when the shell started.
7196
7197 43. The '.' and 'source' builtins do not search the current directory
7198 for the filename argument if it is not found by searching 'PATH'.
7199
7200 44. Enabling POSIX mode has the effect of setting the
7201 'inherit_errexit' option, so subshells spawned to execute command
7202 substitutions inherit the value of the '-e' option from the parent
7203 shell. When the 'inherit_errexit' option is not enabled, Bash
7204 clears the '-e' option in such subshells.
7205
7206 45. Enabling POSIX mode has the effect of setting the 'shift_verbose'
7207 option, so numeric arguments to 'shift' that exceed the number of
7208 positional parameters will result in an error message.
7209
7210 46. When the 'alias' builtin displays alias definitions, it does not
7211 display them with a leading 'alias ' unless the '-p' option is
7212 supplied.
7213
7214 47. When the 'set' builtin is invoked without options, it does not
7215 display shell function names and definitions.
7216
7217 48. When the 'set' builtin is invoked without options, it displays
7218 variable values without quotes, unless they contain shell
7219 metacharacters, even if the result contains nonprinting characters.
7220
7221 49. When the 'cd' builtin is invoked in logical mode, and the pathname
7222 constructed from '$PWD' and the directory name supplied as an
7223 argument does not refer to an existing directory, 'cd' will fail
7224 instead of falling back to physical mode.
7225
7226 50. When the 'cd' builtin cannot change a directory because the length
7227 of the pathname constructed from '$PWD' and the directory name
7228 supplied as an argument exceeds 'PATH_MAX' when all symbolic links
7229 are expanded, 'cd' will fail instead of attempting to use only the
7230 supplied directory name.
7231
7232 51. The 'pwd' builtin verifies that the value it prints is the same as
7233 the current directory, even if it is not asked to check the file
7234 system with the '-P' option.
7235
7236 52. When listing the history, the 'fc' builtin does not include an
7237 indication of whether or not a history entry has been modified.
7238
7239 53. The default editor used by 'fc' is 'ed'.
7240
7241 54. The 'type' and 'command' builtins will not report a non-executable
7242 file as having been found, though the shell will attempt to execute
7243 such a file if it is the only so-named file found in '$PATH'.
7244
7245 55. The 'vi' editing mode will invoke the 'vi' editor directly when
7246 the 'v' command is run, instead of checking '$VISUAL' and
7247 '$EDITOR'.
7248
7249 56. When the 'xpg_echo' option is enabled, Bash does not attempt to
7250 interpret any arguments to 'echo' as options. Each argument is
7251 displayed, after escape characters are converted.
7252
7253 57. The 'ulimit' builtin uses a block size of 512 bytes for the '-c'
7254 and '-f' options.
7255
7256 58. The arrival of 'SIGCHLD' when a trap is set on 'SIGCHLD' does not
7257 interrupt the 'wait' builtin and cause it to return immediately.
7258 The trap command is run once for each child that exits.
7259
7260 59. The 'read' builtin may be interrupted by a signal for which a trap
7261 has been set. If Bash receives a trapped signal while executing
7262 'read', the trap handler executes and 'read' returns an exit status
7263 greater than 128.
7264
7265 60. The 'printf' builtin uses 'double' (via 'strtod') to convert
7266 arguments corresponding to floating point conversion specifiers,
7267 instead of 'long double' if it's available. The 'L' length
7268 modifier forces 'printf' to use 'long double' if it's available.
7269
7270 61. Bash removes an exited background process's status from the list
7271 of such statuses after the 'wait' builtin is used to obtain it.
7272
7273 There is other POSIX behavior that Bash does not implement by default
7274even when in POSIX mode. Specifically:
7275
7276 1. The 'fc' builtin checks '$EDITOR' as a program to edit history
7277 entries if 'FCEDIT' is unset, rather than defaulting directly to
7278 'ed'. 'fc' uses 'ed' if 'EDITOR' is unset.
7279
7280 2. As noted above, Bash requires the 'xpg_echo' option to be enabled
7281 for the 'echo' builtin to be fully conformant.
7282
7283 Bash can be configured to be POSIX-conformant by default, by
7284specifying the '--enable-strict-posix-default' to 'configure' when
7285building (*note Optional Features::).
7286
7287\1f
7288File: bashref.info, Node: Shell Compatibility Mode, Prev: Bash POSIX Mode, Up: Bash Features
7289
72906.12 Shell Compatibility Mode
7291=============================
7292
7293Bash-4.0 introduced the concept of a "shell compatibility level",
7294specified as a set of options to the shopt builtin ('compat31',
7295'compat32', 'compat40', 'compat41', and so on). There is only one
7296current compatibility level - each option is mutually exclusive. The
7297compatibility level is intended to allow users to select behavior from
7298previous versions that is incompatible with newer versions while they
7299migrate scripts to use current features and behavior. It's intended to
7300be a temporary solution.
7301
7302 This section does not mention behavior that is standard for a
7303particular version (e.g., setting 'compat32' means that quoting the rhs
7304of the regexp matching operator quotes special regexp characters in the
7305word, which is default behavior in bash-3.2 and subsequent versions).
7306
7307 If a user enables, say, 'compat32', it may affect the behavior of
7308other compatibility levels up to and including the current compatibility
7309level. The idea is that each compatibility level controls behavior that
7310changed in that version of Bash, but that behavior may have been present
7311in earlier versions. For instance, the change to use locale-based
7312comparisons with the '[[' command came in bash-4.1, and earlier versions
7313used ASCII-based comparisons, so enabling 'compat32' will enable
7314ASCII-based comparisons as well. That granularity may not be sufficient
7315for all uses, and as a result users should employ compatibility levels
7316carefully. Read the documentation for a particular feature to find out
7317the current behavior.
7318
7319 Bash-4.3 introduced a new shell variable: 'BASH_COMPAT'. The value
7320assigned to this variable (a decimal version number like 4.2, or an
7321integer corresponding to the 'compat'NN option, like 42) determines the
7322compatibility level.
7323
7324 Starting with bash-4.4, Bash has begun deprecating older
7325compatibility levels. Eventually, the options will be removed in favor
7326of 'BASH_COMPAT'.
7327
7328 Bash-5.0 is the final version for which there will be an individual
7329shopt option for the previous version. Users should use 'BASH_COMPAT'
7330on bash-5.0 and later versions.
7331
7332 The following table describes the behavior changes controlled by each
7333compatibility level setting. The 'compat'NN tag is used as shorthand
7334for setting the compatibility level to NN using one of the following
7335mechanisms. For versions prior to bash-5.0, the compatibility level may
7336be set using the corresponding 'compat'NN shopt option. For bash-4.3
7337and later versions, the 'BASH_COMPAT' variable is preferred, and it is
7338required for bash-5.1 and later versions.
7339
7340'compat31'
7341 * quoting the rhs of the '[[' command's regexp matching operator
7342 (=~) has no special effect
7343
7344'compat32'
7345 * interrupting a command list such as "a ; b ; c" causes the
7346 execution of the next command in the list (in bash-4.0 and
7347 later versions, the shell acts as if it received the
7348 interrupt, so interrupting one command in a list aborts the
7349 execution of the entire list)
7350
7351'compat40'
7352 * the '<' and '>' operators to the '[[' command do not consider
7353 the current locale when comparing strings; they use ASCII
7354 ordering. Bash versions prior to bash-4.1 use ASCII collation
7355 and strcmp(3); bash-4.1 and later use the current locale's
7356 collation sequence and strcoll(3).
7357
7358'compat41'
7359 * in posix mode, 'time' may be followed by options and still be
7360 recognized as a reserved word (this is POSIX interpretation
7361 267)
7362 * in posix mode, the parser requires that an even number of
7363 single quotes occur in the WORD portion of a double-quoted
7364 ${...} parameter expansion and treats them specially, so that
7365 characters within the single quotes are considered quoted
7366 (this is POSIX interpretation 221)
7367
7368'compat42'
7369 * the replacement string in double-quoted pattern substitution
7370 does not undergo quote removal, as it does in versions after
7371 bash-4.2
7372 * in posix mode, single quotes are considered special when
7373 expanding the WORD portion of a double-quoted ${...} parameter
7374 expansion and can be used to quote a closing brace or other
7375 special character (this is part of POSIX interpretation 221);
7376 in later versions, single quotes are not special within
7377 double-quoted word expansions
7378
7379'compat43'
7380 * the shell does not print a warning message if an attempt is
7381 made to use a quoted compound assignment as an argument to
7382 declare (e.g., declare -a foo='(1 2)'). Later versions warn
7383 that this usage is deprecated
7384 * word expansion errors are considered non-fatal errors that
7385 cause the current command to fail, even in posix mode (the
7386 default behavior is to make them fatal errors that cause the
7387 shell to exit)
7388 * when executing a shell function, the loop state
7389 (while/until/etc.) is not reset, so 'break' or 'continue' in
7390 that function will break or continue loops in the calling
7391 context. Bash-4.4 and later reset the loop state to prevent
7392 this
7393
7394'compat44'
7395 * the shell sets up the values used by 'BASH_ARGV' and
7396 'BASH_ARGC' so they can expand to the shell's positional
7397 parameters even if extended debugging mode is not enabled
7398 * a subshell inherits loops from its parent context, so 'break'
7399 or 'continue' will cause the subshell to exit. Bash-5.0 and
7400 later reset the loop state to prevent the exit
7401 * variable assignments preceding builtins like 'export' and
7402 'readonly' that set attributes continue to affect variables
7403 with the same name in the calling environment even if the
7404 shell is not in posix mode
7405
7406'compat50 (set using BASH_COMPAT)'
7407 * Bash-5.1 changed the way '$RANDOM' is generated to introduce
7408 slightly more randomness. If the shell compatibility level is
7409 set to 50 or lower, it reverts to the method from bash-5.0 and
7410 previous versions, so seeding the random number generator by
7411 assigning a value to 'RANDOM' will produce the same sequence
7412 as in bash-5.0
7413 * If the command hash table is empty, Bash versions prior to
7414 bash-5.1 printed an informational message to that effect, even
7415 when producing output that can be reused as input. Bash-5.1
7416 suppresses that message when the '-l' option is supplied.
7417
7418'compat51 (set using BASH_COMPAT)'
7419 * The 'unset' builtin will unset the array 'a' given an argument
7420 like 'a[@]'. Bash-5.2 will unset an element with key '@'
7421 (associative arrays) or remove all the elements without
7422 unsetting the array (indexed arrays)
7423 * arithmetic commands ( ((...)) ) and the expressions in an
7424 arithmetic for statement can be expanded more than once
7425 * expressions used as arguments to arithmetic operators in the
7426 '[[' conditional command can be expanded more than once
7427 * the expressions in substring parameter brace expansion can be
7428 expanded more than once
7429 * the expressions in the $(( ... )) word expansion can be
7430 expanded more than once
7431 * arithmetic expressions used as indexed array subscripts can be
7432 expanded more than once
7433 * 'test -v', when given an argument of 'A[@]', where A is an
7434 existing associative array, will return true if the array has
7435 any set elements. Bash-5.2 will look for and report on a key
7436 named '@'
7437 * the ${PARAMETER[:]=VALUE} word expansion will return VALUE,
7438 before any variable-specific transformations have been
7439 performed (e.g., converting to lowercase). Bash-5.2 will
7440 return the final value assigned to the variable.
7441 * Parsing command substitutions will behave as if extended glob
7442 (*note The Shopt Builtin::) is enabled, so that parsing a
7443 command substitution containing an extglob pattern (say, as
7444 part of a shell function) will not fail. This assumes the
7445 intent is to enable extglob before the command is executed and
7446 word expansions are performed. It will fail at word expansion
7447 time if extglob hasn't been enabled by the time the command is
7448 executed.
7449
7450\1f
7451File: bashref.info, Node: Job Control, Next: Command Line Editing, Prev: Bash Features, Up: Top
7452
74537 Job Control
7454*************
7455
7456This chapter discusses what job control is, how it works, and how Bash
7457allows you to access its facilities.
7458
7459* Menu:
7460
7461* Job Control Basics:: How job control works.
7462* Job Control Builtins:: Bash builtin commands used to interact
7463 with job control.
7464* Job Control Variables:: Variables Bash uses to customize job
7465 control.
7466
7467\1f
7468File: bashref.info, Node: Job Control Basics, Next: Job Control Builtins, Up: Job Control
7469
74707.1 Job Control Basics
7471======================
7472
7473Job control refers to the ability to selectively stop (suspend) the
7474execution of processes and continue (resume) their execution at a later
7475point. A user typically employs this facility via an interactive
7476interface supplied jointly by the operating system kernel's terminal
7477driver and Bash.
7478
7479 The shell associates a JOB with each pipeline. It keeps a table of
7480currently executing jobs, which may be listed with the 'jobs' command.
7481When Bash starts a job asynchronously, it prints a line that looks like:
7482 [1] 25647
7483indicating that this job is job number 1 and that the process ID of the
7484last process in the pipeline associated with this job is 25647. All of
7485the processes in a single pipeline are members of the same job. Bash
7486uses the JOB abstraction as the basis for job control.
7487
7488 To facilitate the implementation of the user interface to job
7489control, the operating system maintains the notion of a current terminal
7490process group ID. Members of this process group (processes whose
7491process group ID is equal to the current terminal process group ID)
7492receive keyboard-generated signals such as 'SIGINT'. These processes
7493are said to be in the foreground. Background processes are those whose
7494process group ID differs from the terminal's; such processes are immune
7495to keyboard-generated signals. Only foreground processes are allowed to
7496read from or, if the user so specifies with 'stty tostop', write to the
7497terminal. Background processes which attempt to read from (write to
7498when 'stty tostop' is in effect) the terminal are sent a 'SIGTTIN'
7499('SIGTTOU') signal by the kernel's terminal driver, which, unless
7500caught, suspends the process.
7501
7502 If the operating system on which Bash is running supports job
7503control, Bash contains facilities to use it. Typing the "suspend"
7504character (typically '^Z', Control-Z) while a process is running causes
7505that process to be stopped and returns control to Bash. Typing the
7506"delayed suspend" character (typically '^Y', Control-Y) causes the
7507process to be stopped when it attempts to read input from the terminal,
7508and control to be returned to Bash. The user then manipulates the state
7509of this job, using the 'bg' command to continue it in the background,
7510the 'fg' command to continue it in the foreground, or the 'kill' command
7511to kill it. A '^Z' takes effect immediately, and has the additional
7512side effect of causing pending output and typeahead to be discarded.
7513
7514 There are a number of ways to refer to a job in the shell. The
7515character '%' introduces a job specification ("jobspec").
7516
7517 Job number 'n' may be referred to as '%n'. The symbols '%%' and '%+'
7518refer to the shell's notion of the current job, which is the last job
7519stopped while it was in the foreground or started in the background. A
7520single '%' (with no accompanying job specification) also refers to the
7521current job. The previous job may be referenced using '%-'. If there
7522is only a single job, '%+' and '%-' can both be used to refer to that
7523job. In output pertaining to jobs (e.g., the output of the 'jobs'
7524command), the current job is always flagged with a '+', and the previous
7525job with a '-'.
7526
7527 A job may also be referred to using a prefix of the name used to
7528start it, or using a substring that appears in its command line. For
7529example, '%ce' refers to a stopped job whose command name begins with
7530'ce'. Using '%?ce', on the other hand, refers to any job containing the
7531string 'ce' in its command line. If the prefix or substring matches
7532more than one job, Bash reports an error.
7533
7534 Simply naming a job can be used to bring it into the foreground: '%1'
7535is a synonym for 'fg %1', bringing job 1 from the background into the
7536foreground. Similarly, '%1 &' resumes job 1 in the background,
7537equivalent to 'bg %1'
7538
7539 The shell learns immediately whenever a job changes state. Normally,
7540Bash waits until it is about to print a prompt before reporting changes
7541in a job's status so as to not interrupt any other output. If the '-b'
7542option to the 'set' builtin is enabled, Bash reports such changes
7543immediately (*note The Set Builtin::). Any trap on 'SIGCHLD' is
7544executed for each child process that exits.
7545
7546 If an attempt to exit Bash is made while jobs are stopped, (or
7547running, if the 'checkjobs' option is enabled - see *note The Shopt
7548Builtin::), the shell prints a warning message, and if the 'checkjobs'
7549option is enabled, lists the jobs and their statuses. The 'jobs'
7550command may then be used to inspect their status. If a second attempt
7551to exit is made without an intervening command, Bash does not print
7552another warning, and any stopped jobs are terminated.
7553
7554 When the shell is waiting for a job or process using the 'wait'
7555builtin, and job control is enabled, 'wait' will return when the job
7556changes state. The '-f' option causes 'wait' to wait until the job or
7557process terminates before returning.
7558
7559\1f
7560File: bashref.info, Node: Job Control Builtins, Next: Job Control Variables, Prev: Job Control Basics, Up: Job Control
7561
75627.2 Job Control Builtins
7563========================
7564
7565'bg'
7566 bg [JOBSPEC ...]
7567
7568 Resume each suspended job JOBSPEC in the background, as if it had
7569 been started with '&'. If JOBSPEC is not supplied, the current job
7570 is used. The return status is zero unless it is run when job
7571 control is not enabled, or, when run with job control enabled, any
7572 JOBSPEC was not found or specifies a job that was started without
7573 job control.
7574
7575'fg'
7576 fg [JOBSPEC]
7577
7578 Resume the job JOBSPEC in the foreground and make it the current
7579 job. If JOBSPEC is not supplied, the current job is used. The
7580 return status is that of the command placed into the foreground, or
7581 non-zero if run when job control is disabled or, when run with job
7582 control enabled, JOBSPEC does not specify a valid job or JOBSPEC
7583 specifies a job that was started without job control.
7584
7585'jobs'
7586 jobs [-lnprs] [JOBSPEC]
7587 jobs -x COMMAND [ARGUMENTS]
7588
7589 The first form lists the active jobs. The options have the
7590 following meanings:
7591
7592 '-l'
7593 List process IDs in addition to the normal information.
7594
7595 '-n'
7596 Display information only about jobs that have changed status
7597 since the user was last notified of their status.
7598
7599 '-p'
7600 List only the process ID of the job's process group leader.
7601
7602 '-r'
7603 Display only running jobs.
7604
7605 '-s'
7606 Display only stopped jobs.
7607
7608 If JOBSPEC is given, output is restricted to information about that
7609 job. If JOBSPEC is not supplied, the status of all jobs is listed.
7610
7611 If the '-x' option is supplied, 'jobs' replaces any JOBSPEC found
7612 in COMMAND or ARGUMENTS with the corresponding process group ID,
7613 and executes COMMAND, passing it ARGUMENTs, returning its exit
7614 status.
7615
7616'kill'
7617 kill [-s SIGSPEC] [-n SIGNUM] [-SIGSPEC] JOBSPEC or PID
7618 kill -l|-L [EXIT_STATUS]
7619
7620 Send a signal specified by SIGSPEC or SIGNUM to the process named
7621 by job specification JOBSPEC or process ID PID. SIGSPEC is either
7622 a case-insensitive signal name such as 'SIGINT' (with or without
7623 the 'SIG' prefix) or a signal number; SIGNUM is a signal number.
7624 If SIGSPEC and SIGNUM are not present, 'SIGTERM' is used. The '-l'
7625 option lists the signal names. If any arguments are supplied when
7626 '-l' is given, the names of the signals corresponding to the
7627 arguments are listed, and the return status is zero. EXIT_STATUS
7628 is a number specifying a signal number or the exit status of a
7629 process terminated by a signal. The '-L' option is equivalent to
7630 '-l'. The return status is zero if at least one signal was
7631 successfully sent, or non-zero if an error occurs or an invalid
7632 option is encountered.
7633
7634'wait'
7635 wait [-fn] [-p VARNAME] [JOBSPEC or PID ...]
7636
7637 Wait until the child process specified by each process ID PID or
7638 job specification JOBSPEC exits and return the exit status of the
7639 last command waited for. If a job spec is given, all processes in
7640 the job are waited for. If no arguments are given, 'wait' waits
7641 for all running background jobs and the last-executed process
7642 substitution, if its process id is the same as $!, and the return
7643 status is zero. If the '-n' option is supplied, 'wait' waits for a
7644 single job from the list of PIDs or JOBSPECs or, if no arguments
7645 are supplied, any job, to complete and returns its exit status. If
7646 none of the supplied arguments is a child of the shell, or if no
7647 arguments are supplied and the shell has no unwaited-for children,
7648 the exit status is 127. If the '-p' option is supplied, the
7649 process or job identifier of the job for which the exit status is
7650 returned is assigned to the variable VARNAME named by the option
7651 argument. The variable will be unset initially, before any
7652 assignment. This is useful only when the '-n' option is supplied.
7653 Supplying the '-f' option, when job control is enabled, forces
7654 'wait' to wait for each PID or JOBSPEC to terminate before
7655 returning its status, instead of returning when it changes status.
7656 If neither JOBSPEC nor PID specifies an active child process of the
7657 shell, the return status is 127. If 'wait' is interrupted by a
7658 signal, the return status will be greater than 128, as described
7659 above (*note Signals::). Otherwise, the return status is the exit
7660 status of the last process or job waited for.
7661
7662'disown'
7663 disown [-ar] [-h] [JOBSPEC ... | PID ... ]
7664
7665 Without options, remove each JOBSPEC from the table of active jobs.
7666 If the '-h' option is given, the job is not removed from the table,
7667 but is marked so that 'SIGHUP' is not sent to the job if the shell
7668 receives a 'SIGHUP'. If JOBSPEC is not present, and neither the
7669 '-a' nor the '-r' option is supplied, the current job is used. If
7670 no JOBSPEC is supplied, the '-a' option means to remove or mark all
7671 jobs; the '-r' option without a JOBSPEC argument restricts
7672 operation to running jobs.
7673
7674'suspend'
7675 suspend [-f]
7676
7677 Suspend the execution of this shell until it receives a 'SIGCONT'
7678 signal. A login shell, or a shell without job control enabled,
7679 cannot be suspended; the '-f' option can be used to override this
7680 and force the suspension. The return status is 0 unless the shell
7681 is a login shell or job control is not enabled and '-f' is not
7682 supplied.
7683
7684 When job control is not active, the 'kill' and 'wait' builtins do not
7685accept JOBSPEC arguments. They must be supplied process IDs.
7686
7687\1f
7688File: bashref.info, Node: Job Control Variables, Prev: Job Control Builtins, Up: Job Control
7689
76907.3 Job Control Variables
7691=========================
7692
7693'auto_resume'
7694 This variable controls how the shell interacts with the user and
7695 job control. If this variable exists then single word simple
7696 commands without redirections are treated as candidates for
7697 resumption of an existing job. There is no ambiguity allowed; if
7698 there is more than one job beginning with the string typed, then
7699 the most recently accessed job will be selected. The name of a
7700 stopped job, in this context, is the command line used to start it.
7701 If this variable is set to the value 'exact', the string supplied
7702 must match the name of a stopped job exactly; if set to
7703 'substring', the string supplied needs to match a substring of the
7704 name of a stopped job. The 'substring' value provides
7705 functionality analogous to the '%?' job ID (*note Job Control
7706 Basics::). If set to any other value, the supplied string must be
7707 a prefix of a stopped job's name; this provides functionality
7708 analogous to the '%' job ID.
7709
7710\1f
7711File: bashref.info, Node: Command Line Editing, Next: Using History Interactively, Prev: Job Control, Up: Top
7712
77138 Command Line Editing
7714**********************
7715
7716This chapter describes the basic features of the GNU command line
7717editing interface. Command line editing is provided by the Readline
7718library, which is used by several different programs, including Bash.
7719Command line editing is enabled by default when using an interactive
7720shell, unless the '--noediting' option is supplied at shell invocation.
7721Line editing is also used when using the '-e' option to the 'read'
7722builtin command (*note Bash Builtins::). By default, the line editing
7723commands are similar to those of Emacs. A vi-style line editing
7724interface is also available. Line editing can be enabled at any time
7725using the '-o emacs' or '-o vi' options to the 'set' builtin command
7726(*note The Set Builtin::), or disabled using the '+o emacs' or '+o vi'
7727options to 'set'.
7728
7729* Menu:
7730
7731* Introduction and Notation:: Notation used in this text.
7732* Readline Interaction:: The minimum set of commands for editing a line.
7733* Readline Init File:: Customizing Readline from a user's view.
7734* Bindable Readline Commands:: A description of most of the Readline commands
7735 available for binding
7736* Readline vi Mode:: A short description of how to make Readline
7737 behave like the vi editor.
7738* Programmable Completion:: How to specify the possible completions for
7739 a specific command.
7740* Programmable Completion Builtins:: Builtin commands to specify how to
7741 complete arguments for a particular command.
7742* A Programmable Completion Example:: An example shell function for
7743 generating possible completions.
7744
7745\1f
7746File: bashref.info, Node: Introduction and Notation, Next: Readline Interaction, Up: Command Line Editing
7747
77488.1 Introduction to Line Editing
7749================================
7750
7751The following paragraphs describe the notation used to represent
7752keystrokes.
7753
7754 The text 'C-k' is read as 'Control-K' and describes the character
7755produced when the <k> key is pressed while the Control key is depressed.
7756
7757 The text 'M-k' is read as 'Meta-K' and describes the character
7758produced when the Meta key (if you have one) is depressed, and the <k>
7759key is pressed. The Meta key is labeled <ALT> on many keyboards. On
7760keyboards with two keys labeled <ALT> (usually to either side of the
7761space bar), the <ALT> on the left side is generally set to work as a
7762Meta key. The <ALT> key on the right may also be configured to work as
7763a Meta key or may be configured as some other modifier, such as a
7764Compose key for typing accented characters.
7765
7766 If you do not have a Meta or <ALT> key, or another key working as a
7767Meta key, the identical keystroke can be generated by typing <ESC>
7768_first_, and then typing <k>. Either process is known as "metafying"
7769the <k> key.
7770
7771 The text 'M-C-k' is read as 'Meta-Control-k' and describes the
7772character produced by "metafying" 'C-k'.
7773
7774 In addition, several keys have their own names. Specifically, <DEL>,
7775<ESC>, <LFD>, <SPC>, <RET>, and <TAB> all stand for themselves when seen
7776in this text, or in an init file (*note Readline Init File::). If your
7777keyboard lacks a <LFD> key, typing <C-j> will produce the desired
7778character. The <RET> key may be labeled <Return> or <Enter> on some
7779keyboards.
7780
7781\1f
7782File: bashref.info, Node: Readline Interaction, Next: Readline Init File, Prev: Introduction and Notation, Up: Command Line Editing
7783
77848.2 Readline Interaction
7785========================
7786
7787Often during an interactive session you type in a long line of text,
7788only to notice that the first word on the line is misspelled. The
7789Readline library gives you a set of commands for manipulating the text
7790as you type it in, allowing you to just fix your typo, and not forcing
7791you to retype the majority of the line. Using these editing commands,
7792you move the cursor to the place that needs correction, and delete or
7793insert the text of the corrections. Then, when you are satisfied with
7794the line, you simply press <RET>. You do not have to be at the end of
7795the line to press <RET>; the entire line is accepted regardless of the
7796location of the cursor within the line.
7797
7798* Menu:
7799
7800* Readline Bare Essentials:: The least you need to know about Readline.
7801* Readline Movement Commands:: Moving about the input line.
7802* Readline Killing Commands:: How to delete text, and how to get it back!
7803* Readline Arguments:: Giving numeric arguments to commands.
7804* Searching:: Searching through previous lines.
7805
7806\1f
7807File: bashref.info, Node: Readline Bare Essentials, Next: Readline Movement Commands, Up: Readline Interaction
7808
78098.2.1 Readline Bare Essentials
7810------------------------------
7811
7812In order to enter characters into the line, simply type them. The typed
7813character appears where the cursor was, and then the cursor moves one
7814space to the right. If you mistype a character, you can use your erase
7815character to back up and delete the mistyped character.
7816
7817 Sometimes you may mistype a character, and not notice the error until
7818you have typed several other characters. In that case, you can type
7819'C-b' to move the cursor to the left, and then correct your mistake.
7820Afterwards, you can move the cursor to the right with 'C-f'.
7821
7822 When you add text in the middle of a line, you will notice that
7823characters to the right of the cursor are 'pushed over' to make room for
7824the text that you have inserted. Likewise, when you delete text behind
7825the cursor, characters to the right of the cursor are 'pulled back' to
7826fill in the blank space created by the removal of the text. A list of
7827the bare essentials for editing the text of an input line follows.
7828
7829'C-b'
7830 Move back one character.
7831'C-f'
7832 Move forward one character.
7833<DEL> or <Backspace>
7834 Delete the character to the left of the cursor.
7835'C-d'
7836 Delete the character underneath the cursor.
7837Printing characters
7838 Insert the character into the line at the cursor.
7839'C-_' or 'C-x C-u'
7840 Undo the last editing command. You can undo all the way back to an
7841 empty line.
7842
7843(Depending on your configuration, the <Backspace> key might be set to
7844delete the character to the left of the cursor and the <DEL> key set to
7845delete the character underneath the cursor, like 'C-d', rather than the
7846character to the left of the cursor.)
7847
7848\1f
7849File: bashref.info, Node: Readline Movement Commands, Next: Readline Killing Commands, Prev: Readline Bare Essentials, Up: Readline Interaction
7850
78518.2.2 Readline Movement Commands
7852--------------------------------
7853
7854The above table describes the most basic keystrokes that you need in
7855order to do editing of the input line. For your convenience, many other
7856commands have been added in addition to 'C-b', 'C-f', 'C-d', and <DEL>.
7857Here are some commands for moving more rapidly about the line.
7858
7859'C-a'
7860 Move to the start of the line.
7861'C-e'
7862 Move to the end of the line.
7863'M-f'
7864 Move forward a word, where a word is composed of letters and
7865 digits.
7866'M-b'
7867 Move backward a word.
7868'C-l'
7869 Clear the screen, reprinting the current line at the top.
7870
7871 Notice how 'C-f' moves forward a character, while 'M-f' moves forward
7872a word. It is a loose convention that control keystrokes operate on
7873characters while meta keystrokes operate on words.
7874
7875\1f
7876File: bashref.info, Node: Readline Killing Commands, Next: Readline Arguments, Prev: Readline Movement Commands, Up: Readline Interaction
7877
78788.2.3 Readline Killing Commands
7879-------------------------------
7880
7881"Killing" text means to delete the text from the line, but to save it
7882away for later use, usually by "yanking" (re-inserting) it back into the
7883line. ('Cut' and 'paste' are more recent jargon for 'kill' and 'yank'.)
7884
7885 If the description for a command says that it 'kills' text, then you
7886can be sure that you can get the text back in a different (or the same)
7887place later.
7888
7889 When you use a kill command, the text is saved in a "kill-ring". Any
7890number of consecutive kills save all of the killed text together, so
7891that when you yank it back, you get it all. The kill ring is not line
7892specific; the text that you killed on a previously typed line is
7893available to be yanked back later, when you are typing another line.
7894
7895 Here is the list of commands for killing text.
7896
7897'C-k'
7898 Kill the text from the current cursor position to the end of the
7899 line.
7900
7901'M-d'
7902 Kill from the cursor to the end of the current word, or, if between
7903 words, to the end of the next word. Word boundaries are the same
7904 as those used by 'M-f'.
7905
7906'M-<DEL>'
7907 Kill from the cursor to the start of the current word, or, if
7908 between words, to the start of the previous word. Word boundaries
7909 are the same as those used by 'M-b'.
7910
7911'C-w'
7912 Kill from the cursor to the previous whitespace. This is different
7913 than 'M-<DEL>' because the word boundaries differ.
7914
7915 Here is how to "yank" the text back into the line. Yanking means to
7916copy the most-recently-killed text from the kill buffer.
7917
7918'C-y'
7919 Yank the most recently killed text back into the buffer at the
7920 cursor.
7921
7922'M-y'
7923 Rotate the kill-ring, and yank the new top. You can only do this
7924 if the prior command is 'C-y' or 'M-y'.
7925
7926\1f
7927File: bashref.info, Node: Readline Arguments, Next: Searching, Prev: Readline Killing Commands, Up: Readline Interaction
7928
79298.2.4 Readline Arguments
7930------------------------
7931
7932You can pass numeric arguments to Readline commands. Sometimes the
7933argument acts as a repeat count, other times it is the sign of the
7934argument that is significant. If you pass a negative argument to a
7935command which normally acts in a forward direction, that command will
7936act in a backward direction. For example, to kill text back to the
7937start of the line, you might type 'M-- C-k'.
7938
7939 The general way to pass numeric arguments to a command is to type
7940meta digits before the command. If the first 'digit' typed is a minus
7941sign ('-'), then the sign of the argument will be negative. Once you
7942have typed one meta digit to get the argument started, you can type the
7943remainder of the digits, and then the command. For example, to give the
7944'C-d' command an argument of 10, you could type 'M-1 0 C-d', which will
7945delete the next ten characters on the input line.
7946
7947\1f
7948File: bashref.info, Node: Searching, Prev: Readline Arguments, Up: Readline Interaction
7949
79508.2.5 Searching for Commands in the History
7951-------------------------------------------
7952
7953Readline provides commands for searching through the command history
7954(*note Bash History Facilities::) for lines containing a specified
7955string. There are two search modes: "incremental" and
7956"non-incremental".
7957
7958 Incremental searches begin before the user has finished typing the
7959search string. As each character of the search string is typed,
7960Readline displays the next entry from the history matching the string
7961typed so far. An incremental search requires only as many characters as
7962needed to find the desired history entry. To search backward in the
7963history for a particular string, type 'C-r'. Typing 'C-s' searches
7964forward through the history. The characters present in the value of the
7965'isearch-terminators' variable are used to terminate an incremental
7966search. If that variable has not been assigned a value, the <ESC> and
7967'C-J' characters will terminate an incremental search. 'C-g' will abort
7968an incremental search and restore the original line. When the search is
7969terminated, the history entry containing the search string becomes the
7970current line.
7971
7972 To find other matching entries in the history list, type 'C-r' or
7973'C-s' as appropriate. This will search backward or forward in the
7974history for the next entry matching the search string typed so far. Any
7975other key sequence bound to a Readline command will terminate the search
7976and execute that command. For instance, a <RET> will terminate the
7977search and accept the line, thereby executing the command from the
7978history list. A movement command will terminate the search, make the
7979last line found the current line, and begin editing.
7980
7981 Readline remembers the last incremental search string. If two 'C-r's
7982are typed without any intervening characters defining a new search
7983string, any remembered search string is used.
7984
7985 Non-incremental searches read the entire search string before
7986starting to search for matching history lines. The search string may be
7987typed by the user or be part of the contents of the current line.
7988
7989\1f
7990File: bashref.info, Node: Readline Init File, Next: Bindable Readline Commands, Prev: Readline Interaction, Up: Command Line Editing
7991
79928.3 Readline Init File
7993======================
7994
7995Although the Readline library comes with a set of Emacs-like keybindings
7996installed by default, it is possible to use a different set of
7997keybindings. Any user can customize programs that use Readline by
7998putting commands in an "inputrc" file, conventionally in their home
7999directory. The name of this file is taken from the value of the shell
8000variable 'INPUTRC'. If that variable is unset, the default is
8001'~/.inputrc'. If that file does not exist or cannot be read, the
8002ultimate default is '/etc/inputrc'. The 'bind' builtin command can also
8003be used to set Readline keybindings and variables. *Note Bash
8004Builtins::.
8005
8006 When a program which uses the Readline library starts up, the init
8007file is read, and the key bindings are set.
8008
8009 In addition, the 'C-x C-r' command re-reads this init file, thus
8010incorporating any changes that you might have made to it.
8011
8012* Menu:
8013
8014* Readline Init File Syntax:: Syntax for the commands in the inputrc file.
8015
8016* Conditional Init Constructs:: Conditional key bindings in the inputrc file.
8017
8018* Sample Init File:: An example inputrc file.
8019
8020\1f
8021File: bashref.info, Node: Readline Init File Syntax, Next: Conditional Init Constructs, Up: Readline Init File
8022
80238.3.1 Readline Init File Syntax
8024-------------------------------
8025
8026There are only a few basic constructs allowed in the Readline init file.
8027Blank lines are ignored. Lines beginning with a '#' are comments.
8028Lines beginning with a '$' indicate conditional constructs (*note
8029Conditional Init Constructs::). Other lines denote variable settings
8030and key bindings.
8031
8032Variable Settings
8033 You can modify the run-time behavior of Readline by altering the
8034 values of variables in Readline using the 'set' command within the
8035 init file. The syntax is simple:
8036
8037 set VARIABLE VALUE
8038
8039 Here, for example, is how to change from the default Emacs-like key
8040 binding to use 'vi' line editing commands:
8041
8042 set editing-mode vi
8043
8044 Variable names and values, where appropriate, are recognized
8045 without regard to case. Unrecognized variable names are ignored.
8046
8047 Boolean variables (those that can be set to on or off) are set to
8048 on if the value is null or empty, ON (case-insensitive), or 1. Any
8049 other value results in the variable being set to off.
8050
8051 The 'bind -V' command lists the current Readline variable names and
8052 values. *Note Bash Builtins::.
8053
8054 A great deal of run-time behavior is changeable with the following
8055 variables.
8056
8057 'active-region-start-color'
8058 A string variable that controls the text color and background
8059 when displaying the text in the active region (see the
8060 description of 'enable-active-region' below). This string
8061 must not take up any physical character positions on the
8062 display, so it should consist only of terminal escape
8063 sequences. It is output to the terminal before displaying the
8064 text in the active region. This variable is reset to the
8065 default value whenever the terminal type changes. The default
8066 value is the string that puts the terminal in standout mode,
8067 as obtained from the terminal's terminfo description. A
8068 sample value might be '\e[01;33m'.
8069
8070 'active-region-end-color'
8071 A string variable that "undoes" the effects of
8072 'active-region-start-color' and restores "normal" terminal
8073 display appearance after displaying text in the active region.
8074 This string must not take up any physical character positions
8075 on the display, so it should consist only of terminal escape
8076 sequences. It is output to the terminal after displaying the
8077 text in the active region. This variable is reset to the
8078 default value whenever the terminal type changes. The default
8079 value is the string that restores the terminal from standout
8080 mode, as obtained from the terminal's terminfo description. A
8081 sample value might be '\e[0m'.
8082
8083 'bell-style'
8084 Controls what happens when Readline wants to ring the terminal
8085 bell. If set to 'none', Readline never rings the bell. If
8086 set to 'visible', Readline uses a visible bell if one is
8087 available. If set to 'audible' (the default), Readline
8088 attempts to ring the terminal's bell.
8089
8090 'bind-tty-special-chars'
8091 If set to 'on' (the default), Readline attempts to bind the
8092 control characters treated specially by the kernel's terminal
8093 driver to their Readline equivalents.
8094
8095 'blink-matching-paren'
8096 If set to 'on', Readline attempts to briefly move the cursor
8097 to an opening parenthesis when a closing parenthesis is
8098 inserted. The default is 'off'.
8099
8100 'colored-completion-prefix'
8101 If set to 'on', when listing completions, Readline displays
8102 the common prefix of the set of possible completions using a
8103 different color. The color definitions are taken from the
8104 value of the 'LS_COLORS' environment variable. If there is a
8105 color definition in 'LS_COLORS' for the custom suffix
8106 'readline-colored-completion-prefix', Readline uses this color
8107 for the common prefix instead of its default. The default is
8108 'off'.
8109
8110 'colored-stats'
8111 If set to 'on', Readline displays possible completions using
8112 different colors to indicate their file type. The color
8113 definitions are taken from the value of the 'LS_COLORS'
8114 environment variable. The default is 'off'.
8115
8116 'comment-begin'
8117 The string to insert at the beginning of the line when the
8118 'insert-comment' command is executed. The default value is
8119 '"#"'.
8120
8121 'completion-display-width'
8122 The number of screen columns used to display possible matches
8123 when performing completion. The value is ignored if it is
8124 less than 0 or greater than the terminal screen width. A
8125 value of 0 will cause matches to be displayed one per line.
8126 The default value is -1.
8127
8128 'completion-ignore-case'
8129 If set to 'on', Readline performs filename matching and
8130 completion in a case-insensitive fashion. The default value
8131 is 'off'.
8132
8133 'completion-map-case'
8134 If set to 'on', and COMPLETION-IGNORE-CASE is enabled,
8135 Readline treats hyphens ('-') and underscores ('_') as
8136 equivalent when performing case-insensitive filename matching
8137 and completion. The default value is 'off'.
8138
8139 'completion-prefix-display-length'
8140 The length in characters of the common prefix of a list of
8141 possible completions that is displayed without modification.
8142 When set to a value greater than zero, common prefixes longer
8143 than this value are replaced with an ellipsis when displaying
8144 possible completions.
8145
8146 'completion-query-items'
8147 The number of possible completions that determines when the
8148 user is asked whether the list of possibilities should be
8149 displayed. If the number of possible completions is greater
8150 than or equal to this value, Readline will ask whether or not
8151 the user wishes to view them; otherwise, they are simply
8152 listed. This variable must be set to an integer value greater
8153 than or equal to zero. A zero value means Readline should
8154 never ask; negative values are treated as zero. The default
8155 limit is '100'.
8156
8157 'convert-meta'
8158 If set to 'on', Readline will convert characters with the
8159 eighth bit set to an ASCII key sequence by stripping the
8160 eighth bit and prefixing an <ESC> character, converting them
8161 to a meta-prefixed key sequence. The default value is 'on',
8162 but will be set to 'off' if the locale is one that contains
8163 eight-bit characters. This variable is dependent on the
8164 'LC_CTYPE' locale category, and may change if the locale is
8165 changed.
8166
8167 'disable-completion'
8168 If set to 'On', Readline will inhibit word completion.
8169 Completion characters will be inserted into the line as if
8170 they had been mapped to 'self-insert'. The default is 'off'.
8171
8172 'echo-control-characters'
8173 When set to 'on', on operating systems that indicate they
8174 support it, Readline echoes a character corresponding to a
8175 signal generated from the keyboard. The default is 'on'.
8176
8177 'editing-mode'
8178 The 'editing-mode' variable controls which default set of key
8179 bindings is used. By default, Readline starts up in Emacs
8180 editing mode, where the keystrokes are most similar to Emacs.
8181 This variable can be set to either 'emacs' or 'vi'.
8182
8183 'emacs-mode-string'
8184 If the SHOW-MODE-IN-PROMPT variable is enabled, this string is
8185 displayed immediately before the last line of the primary
8186 prompt when emacs editing mode is active. The value is
8187 expanded like a key binding, so the standard set of meta- and
8188 control prefixes and backslash escape sequences is available.
8189 Use the '\1' and '\2' escapes to begin and end sequences of
8190 non-printing characters, which can be used to embed a terminal
8191 control sequence into the mode string. The default is '@'.
8192
8193 'enable-active-region'
8194 The "point" is the current cursor position, and "mark" refers
8195 to a saved cursor position (*note Commands For Moving::). The
8196 text between the point and mark is referred to as the
8197 "region". When this variable is set to 'On', Readline allows
8198 certain commands to designate the region as "active". When
8199 the region is active, Readline highlights the text in the
8200 region using the value of the 'active-region-start-color',
8201 which defaults to the string that enables the terminal's
8202 standout mode. The active region shows the text inserted by
8203 bracketed-paste and any matching text found by incremental and
8204 non-incremental history searches. The default is 'On'.
8205
8206 'enable-bracketed-paste'
8207 When set to 'On', Readline configures the terminal to insert
8208 each paste into the editing buffer as a single string of
8209 characters, instead of treating each character as if it had
8210 been read from the keyboard. This is called putting the
8211 terminal into "bracketed paste mode"; it prevents Readline
8212 from executing any editing commands bound to key sequences
8213 appearing in the pasted text. The default is 'On'.
8214
8215 'enable-keypad'
8216 When set to 'on', Readline will try to enable the application
8217 keypad when it is called. Some systems need this to enable
8218 the arrow keys. The default is 'off'.
8219
8220 'enable-meta-key'
8221 When set to 'on', Readline will try to enable any meta
8222 modifier key the terminal claims to support when it is called.
8223 On many terminals, the meta key is used to send eight-bit
8224 characters. The default is 'on'.
8225
8226 'expand-tilde'
8227 If set to 'on', tilde expansion is performed when Readline
8228 attempts word completion. The default is 'off'.
8229
8230 'history-preserve-point'
8231 If set to 'on', the history code attempts to place the point
8232 (the current cursor position) at the same location on each
8233 history line retrieved with 'previous-history' or
8234 'next-history'. The default is 'off'.
8235
8236 'history-size'
8237 Set the maximum number of history entries saved in the history
8238 list. If set to zero, any existing history entries are
8239 deleted and no new entries are saved. If set to a value less
8240 than zero, the number of history entries is not limited. By
8241 default, the number of history entries is not limited. If an
8242 attempt is made to set HISTORY-SIZE to a non-numeric value,
8243 the maximum number of history entries will be set to 500.
8244
8245 'horizontal-scroll-mode'
8246 This variable can be set to either 'on' or 'off'. Setting it
8247 to 'on' means that the text of the lines being edited will
8248 scroll horizontally on a single screen line when they are
8249 longer than the width of the screen, instead of wrapping onto
8250 a new screen line. This variable is automatically set to 'on'
8251 for terminals of height 1. By default, this variable is set
8252 to 'off'.
8253
8254 'input-meta'
8255 If set to 'on', Readline will enable eight-bit input (it will
8256 not clear the eighth bit in the characters it reads),
8257 regardless of what the terminal claims it can support. The
8258 default value is 'off', but Readline will set it to 'on' if
8259 the locale contains eight-bit characters. The name
8260 'meta-flag' is a synonym for this variable. This variable is
8261 dependent on the 'LC_CTYPE' locale category, and may change if
8262 the locale is changed.
8263
8264 'isearch-terminators'
8265 The string of characters that should terminate an incremental
8266 search without subsequently executing the character as a
8267 command (*note Searching::). If this variable has not been
8268 given a value, the characters <ESC> and 'C-J' will terminate
8269 an incremental search.
8270
8271 'keymap'
8272 Sets Readline's idea of the current keymap for key binding
8273 commands. Built-in 'keymap' names are 'emacs',
8274 'emacs-standard', 'emacs-meta', 'emacs-ctlx', 'vi', 'vi-move',
8275 'vi-command', and 'vi-insert'. 'vi' is equivalent to
8276 'vi-command' ('vi-move' is also a synonym); 'emacs' is
8277 equivalent to 'emacs-standard'. Applications may add
8278 additional names. The default value is 'emacs'. The value of
8279 the 'editing-mode' variable also affects the default keymap.
8280
8281 'keyseq-timeout'
8282 Specifies the duration Readline will wait for a character when
8283 reading an ambiguous key sequence (one that can form a
8284 complete key sequence using the input read so far, or can take
8285 additional input to complete a longer key sequence). If no
8286 input is received within the timeout, Readline will use the
8287 shorter but complete key sequence. Readline uses this value
8288 to determine whether or not input is available on the current
8289 input source ('rl_instream' by default). The value is
8290 specified in milliseconds, so a value of 1000 means that
8291 Readline will wait one second for additional input. If this
8292 variable is set to a value less than or equal to zero, or to a
8293 non-numeric value, Readline will wait until another key is
8294 pressed to decide which key sequence to complete. The default
8295 value is '500'.
8296
8297 'mark-directories'
8298 If set to 'on', completed directory names have a slash
8299 appended. The default is 'on'.
8300
8301 'mark-modified-lines'
8302 This variable, when set to 'on', causes Readline to display an
8303 asterisk ('*') at the start of history lines which have been
8304 modified. This variable is 'off' by default.
8305
8306 'mark-symlinked-directories'
8307 If set to 'on', completed names which are symbolic links to
8308 directories have a slash appended (subject to the value of
8309 'mark-directories'). The default is 'off'.
8310
8311 'match-hidden-files'
8312 This variable, when set to 'on', causes Readline to match
8313 files whose names begin with a '.' (hidden files) when
8314 performing filename completion. If set to 'off', the leading
8315 '.' must be supplied by the user in the filename to be
8316 completed. This variable is 'on' by default.
8317
8318 'menu-complete-display-prefix'
8319 If set to 'on', menu completion displays the common prefix of
8320 the list of possible completions (which may be empty) before
8321 cycling through the list. The default is 'off'.
8322
8323 'output-meta'
8324 If set to 'on', Readline will display characters with the
8325 eighth bit set directly rather than as a meta-prefixed escape
8326 sequence. The default is 'off', but Readline will set it to
8327 'on' if the locale contains eight-bit characters. This
8328 variable is dependent on the 'LC_CTYPE' locale category, and
8329 may change if the locale is changed.
8330
8331 'page-completions'
8332 If set to 'on', Readline uses an internal 'more'-like pager to
8333 display a screenful of possible completions at a time. This
8334 variable is 'on' by default.
8335
8336 'print-completions-horizontally'
8337 If set to 'on', Readline will display completions with matches
8338 sorted horizontally in alphabetical order, rather than down
8339 the screen. The default is 'off'.
8340
8341 'revert-all-at-newline'
8342 If set to 'on', Readline will undo all changes to history
8343 lines before returning when 'accept-line' is executed. By
8344 default, history lines may be modified and retain individual
8345 undo lists across calls to 'readline()'. The default is
8346 'off'.
8347
8348 'show-all-if-ambiguous'
8349 This alters the default behavior of the completion functions.
8350 If set to 'on', words which have more than one possible
8351 completion cause the matches to be listed immediately instead
8352 of ringing the bell. The default value is 'off'.
8353
8354 'show-all-if-unmodified'
8355 This alters the default behavior of the completion functions
8356 in a fashion similar to SHOW-ALL-IF-AMBIGUOUS. If set to
8357 'on', words which have more than one possible completion
8358 without any possible partial completion (the possible
8359 completions don't share a common prefix) cause the matches to
8360 be listed immediately instead of ringing the bell. The
8361 default value is 'off'.
8362
8363 'show-mode-in-prompt'
8364 If set to 'on', add a string to the beginning of the prompt
8365 indicating the editing mode: emacs, vi command, or vi
8366 insertion. The mode strings are user-settable (e.g.,
8367 EMACS-MODE-STRING). The default value is 'off'.
8368
8369 'skip-completed-text'
8370 If set to 'on', this alters the default completion behavior
8371 when inserting a single match into the line. It's only active
8372 when performing completion in the middle of a word. If
8373 enabled, Readline does not insert characters from the
8374 completion that match characters after point in the word being
8375 completed, so portions of the word following the cursor are
8376 not duplicated. For instance, if this is enabled, attempting
8377 completion when the cursor is after the 'e' in 'Makefile' will
8378 result in 'Makefile' rather than 'Makefilefile', assuming
8379 there is a single possible completion. The default value is
8380 'off'.
8381
8382 'vi-cmd-mode-string'
8383 If the SHOW-MODE-IN-PROMPT variable is enabled, this string is
8384 displayed immediately before the last line of the primary
8385 prompt when vi editing mode is active and in command mode.
8386 The value is expanded like a key binding, so the standard set
8387 of meta- and control prefixes and backslash escape sequences
8388 is available. Use the '\1' and '\2' escapes to begin and end
8389 sequences of non-printing characters, which can be used to
8390 embed a terminal control sequence into the mode string. The
8391 default is '(cmd)'.
8392
8393 'vi-ins-mode-string'
8394 If the SHOW-MODE-IN-PROMPT variable is enabled, this string is
8395 displayed immediately before the last line of the primary
8396 prompt when vi editing mode is active and in insertion mode.
8397 The value is expanded like a key binding, so the standard set
8398 of meta- and control prefixes and backslash escape sequences
8399 is available. Use the '\1' and '\2' escapes to begin and end
8400 sequences of non-printing characters, which can be used to
8401 embed a terminal control sequence into the mode string. The
8402 default is '(ins)'.
8403
8404 'visible-stats'
8405 If set to 'on', a character denoting a file's type is appended
8406 to the filename when listing possible completions. The
8407 default is 'off'.
8408
8409Key Bindings
8410 The syntax for controlling key bindings in the init file is simple.
8411 First you need to find the name of the command that you want to
8412 change. The following sections contain tables of the command name,
8413 the default keybinding, if any, and a short description of what the
8414 command does.
8415
8416 Once you know the name of the command, simply place on a line in
8417 the init file the name of the key you wish to bind the command to,
8418 a colon, and then the name of the command. There can be no space
8419 between the key name and the colon - that will be interpreted as
8420 part of the key name. The name of the key can be expressed in
8421 different ways, depending on what you find most comfortable.
8422
8423 In addition to command names, Readline allows keys to be bound to a
8424 string that is inserted when the key is pressed (a MACRO).
8425
8426 The 'bind -p' command displays Readline function names and bindings
8427 in a format that can be put directly into an initialization file.
8428 *Note Bash Builtins::.
8429
8430 KEYNAME: FUNCTION-NAME or MACRO
8431 KEYNAME is the name of a key spelled out in English. For
8432 example:
8433 Control-u: universal-argument
8434 Meta-Rubout: backward-kill-word
8435 Control-o: "> output"
8436
8437 In the example above, 'C-u' is bound to the function
8438 'universal-argument', 'M-DEL' is bound to the function
8439 'backward-kill-word', and 'C-o' is bound to run the macro
8440 expressed on the right hand side (that is, to insert the text
8441 '> output' into the line).
8442
8443 A number of symbolic character names are recognized while
8444 processing this key binding syntax: DEL, ESC, ESCAPE, LFD,
8445 NEWLINE, RET, RETURN, RUBOUT, SPACE, SPC, and TAB.
8446
8447 "KEYSEQ": FUNCTION-NAME or MACRO
8448 KEYSEQ differs from KEYNAME above in that strings denoting an
8449 entire key sequence can be specified, by placing the key
8450 sequence in double quotes. Some GNU Emacs style key escapes
8451 can be used, as in the following example, but the special
8452 character names are not recognized.
8453
8454 "\C-u": universal-argument
8455 "\C-x\C-r": re-read-init-file
8456 "\e[11~": "Function Key 1"
8457
8458 In the above example, 'C-u' is again bound to the function
8459 'universal-argument' (just as it was in the first example),
8460 ''C-x' 'C-r'' is bound to the function 're-read-init-file',
8461 and '<ESC> <[> <1> <1> <~>' is bound to insert the text
8462 'Function Key 1'.
8463
8464 The following GNU Emacs style escape sequences are available when
8465 specifying key sequences:
8466
8467 '\C-'
8468 control prefix
8469 '\M-'
8470 meta prefix
8471 '\e'
8472 an escape character
8473 '\\'
8474 backslash
8475 '\"'
8476 <">, a double quotation mark
8477 '\''
8478 <'>, a single quote or apostrophe
8479
8480 In addition to the GNU Emacs style escape sequences, a second set
8481 of backslash escapes is available:
8482
8483 '\a'
8484 alert (bell)
8485 '\b'
8486 backspace
8487 '\d'
8488 delete
8489 '\f'
8490 form feed
8491 '\n'
8492 newline
8493 '\r'
8494 carriage return
8495 '\t'
8496 horizontal tab
8497 '\v'
8498 vertical tab
8499 '\NNN'
8500 the eight-bit character whose value is the octal value NNN
8501 (one to three digits)
8502 '\xHH'
8503 the eight-bit character whose value is the hexadecimal value
8504 HH (one or two hex digits)
8505
8506 When entering the text of a macro, single or double quotes must be
8507 used to indicate a macro definition. Unquoted text is assumed to
8508 be a function name. In the macro body, the backslash escapes
8509 described above are expanded. Backslash will quote any other
8510 character in the macro text, including '"' and '''. For example,
8511 the following binding will make ''C-x' \' insert a single '\' into
8512 the line:
8513 "\C-x\\": "\\"
8514
8515\1f
8516File: bashref.info, Node: Conditional Init Constructs, Next: Sample Init File, Prev: Readline Init File Syntax, Up: Readline Init File
8517
85188.3.2 Conditional Init Constructs
8519---------------------------------
8520
8521Readline implements a facility similar in spirit to the conditional
8522compilation features of the C preprocessor which allows key bindings and
8523variable settings to be performed as the result of tests. There are
8524four parser directives used.
8525
8526'$if'
8527 The '$if' construct allows bindings to be made based on the editing
8528 mode, the terminal being used, or the application using Readline.
8529 The text of the test, after any comparison operator, extends to the
8530 end of the line; unless otherwise noted, no characters are required
8531 to isolate it.
8532
8533 'mode'
8534 The 'mode=' form of the '$if' directive is used to test
8535 whether Readline is in 'emacs' or 'vi' mode. This may be used
8536 in conjunction with the 'set keymap' command, for instance, to
8537 set bindings in the 'emacs-standard' and 'emacs-ctlx' keymaps
8538 only if Readline is starting out in 'emacs' mode.
8539
8540 'term'
8541 The 'term=' form may be used to include terminal-specific key
8542 bindings, perhaps to bind the key sequences output by the
8543 terminal's function keys. The word on the right side of the
8544 '=' is tested against both the full name of the terminal and
8545 the portion of the terminal name before the first '-'. This
8546 allows 'sun' to match both 'sun' and 'sun-cmd', for instance.
8547
8548 'version'
8549 The 'version' test may be used to perform comparisons against
8550 specific Readline versions. The 'version' expands to the
8551 current Readline version. The set of comparison operators
8552 includes '=' (and '=='), '!=', '<=', '>=', '<', and '>'. The
8553 version number supplied on the right side of the operator
8554 consists of a major version number, an optional decimal point,
8555 and an optional minor version (e.g., '7.1'). If the minor
8556 version is omitted, it is assumed to be '0'. The operator may
8557 be separated from the string 'version' and from the version
8558 number argument by whitespace. The following example sets a
8559 variable if the Readline version being used is 7.0 or newer:
8560 $if version >= 7.0
8561 set show-mode-in-prompt on
8562 $endif
8563
8564 'application'
8565 The APPLICATION construct is used to include
8566 application-specific settings. Each program using the
8567 Readline library sets the APPLICATION NAME, and you can test
8568 for a particular value. This could be used to bind key
8569 sequences to functions useful for a specific program. For
8570 instance, the following command adds a key sequence that
8571 quotes the current or previous word in Bash:
8572 $if Bash
8573 # Quote the current or previous word
8574 "\C-xq": "\eb\"\ef\""
8575 $endif
8576
8577 'variable'
8578 The VARIABLE construct provides simple equality tests for
8579 Readline variables and values. The permitted comparison
8580 operators are '=', '==', and '!='. The variable name must be
8581 separated from the comparison operator by whitespace; the
8582 operator may be separated from the value on the right hand
8583 side by whitespace. Both string and boolean variables may be
8584 tested. Boolean variables must be tested against the values
8585 ON and OFF. The following example is equivalent to the
8586 'mode=emacs' test described above:
8587 $if editing-mode == emacs
8588 set show-mode-in-prompt on
8589 $endif
8590
8591'$endif'
8592 This command, as seen in the previous example, terminates an '$if'
8593 command.
8594
8595'$else'
8596 Commands in this branch of the '$if' directive are executed if the
8597 test fails.
8598
8599'$include'
8600 This directive takes a single filename as an argument and reads
8601 commands and bindings from that file. For example, the following
8602 directive reads from '/etc/inputrc':
8603 $include /etc/inputrc
8604
8605\1f
8606File: bashref.info, Node: Sample Init File, Prev: Conditional Init Constructs, Up: Readline Init File
8607
86088.3.3 Sample Init File
8609----------------------
8610
8611Here is an example of an INPUTRC file. This illustrates key binding,
8612variable assignment, and conditional syntax.
8613
8614 # This file controls the behaviour of line input editing for
8615 # programs that use the GNU Readline library. Existing
8616 # programs include FTP, Bash, and GDB.
8617 #
8618 # You can re-read the inputrc file with C-x C-r.
8619 # Lines beginning with '#' are comments.
8620 #
8621 # First, include any system-wide bindings and variable
8622 # assignments from /etc/Inputrc
8623 $include /etc/Inputrc
8624
8625 #
8626 # Set various bindings for emacs mode.
8627
8628 set editing-mode emacs
8629
8630 $if mode=emacs
8631
8632 Meta-Control-h: backward-kill-word Text after the function name is ignored
8633
8634 #
8635 # Arrow keys in keypad mode
8636 #
8637 #"\M-OD": backward-char
8638 #"\M-OC": forward-char
8639 #"\M-OA": previous-history
8640 #"\M-OB": next-history
8641 #
8642 # Arrow keys in ANSI mode
8643 #
8644 "\M-[D": backward-char
8645 "\M-[C": forward-char
8646 "\M-[A": previous-history
8647 "\M-[B": next-history
8648 #
8649 # Arrow keys in 8 bit keypad mode
8650 #
8651 #"\M-\C-OD": backward-char
8652 #"\M-\C-OC": forward-char
8653 #"\M-\C-OA": previous-history
8654 #"\M-\C-OB": next-history
8655 #
8656 # Arrow keys in 8 bit ANSI mode
8657 #
8658 #"\M-\C-[D": backward-char
8659 #"\M-\C-[C": forward-char
8660 #"\M-\C-[A": previous-history
8661 #"\M-\C-[B": next-history
8662
8663 C-q: quoted-insert
8664
8665 $endif
8666
8667 # An old-style binding. This happens to be the default.
8668 TAB: complete
8669
8670 # Macros that are convenient for shell interaction
8671 $if Bash
8672 # edit the path
8673 "\C-xp": "PATH=${PATH}\e\C-e\C-a\ef\C-f"
8674 # prepare to type a quoted word --
8675 # insert open and close double quotes
8676 # and move to just after the open quote
8677 "\C-x\"": "\"\"\C-b"
8678 # insert a backslash (testing backslash escapes
8679 # in sequences and macros)
8680 "\C-x\\": "\\"
8681 # Quote the current or previous word
8682 "\C-xq": "\eb\"\ef\""
8683 # Add a binding to refresh the line, which is unbound
8684 "\C-xr": redraw-current-line
8685 # Edit variable on current line.
8686 "\M-\C-v": "\C-a\C-k$\C-y\M-\C-e\C-a\C-y="
8687 $endif
8688
8689 # use a visible bell if one is available
8690 set bell-style visible
8691
8692 # don't strip characters to 7 bits when reading
8693 set input-meta on
8694
8695 # allow iso-latin1 characters to be inserted rather
8696 # than converted to prefix-meta sequences
8697 set convert-meta off
8698
8699 # display characters with the eighth bit set directly
8700 # rather than as meta-prefixed characters
8701 set output-meta on
8702
8703 # if there are 150 or more possible completions for a word,
8704 # ask whether or not the user wants to see all of them
8705 set completion-query-items 150
8706
8707 # For FTP
8708 $if Ftp
8709 "\C-xg": "get \M-?"
8710 "\C-xt": "put \M-?"
8711 "\M-.": yank-last-arg
8712 $endif
8713
8714\1f
8715File: bashref.info, Node: Bindable Readline Commands, Next: Readline vi Mode, Prev: Readline Init File, Up: Command Line Editing
8716
87178.4 Bindable Readline Commands
8718==============================
8719
8720* Menu:
8721
8722* Commands For Moving:: Moving about the line.
8723* Commands For History:: Getting at previous lines.
8724* Commands For Text:: Commands for changing text.
8725* Commands For Killing:: Commands for killing and yanking.
8726* Numeric Arguments:: Specifying numeric arguments, repeat counts.
8727* Commands For Completion:: Getting Readline to do the typing for you.
8728* Keyboard Macros:: Saving and re-executing typed characters
8729* Miscellaneous Commands:: Other miscellaneous commands.
8730
8731This section describes Readline commands that may be bound to key
8732sequences. You can list your key bindings by executing 'bind -P' or,
8733for a more terse format, suitable for an INPUTRC file, 'bind -p'.
8734(*Note Bash Builtins::.) Command names without an accompanying key
8735sequence are unbound by default.
8736
8737 In the following descriptions, "point" refers to the current cursor
8738position, and "mark" refers to a cursor position saved by the 'set-mark'
8739command. The text between the point and mark is referred to as the
8740"region".
8741
8742\1f
8743File: bashref.info, Node: Commands For Moving, Next: Commands For History, Up: Bindable Readline Commands
8744
87458.4.1 Commands For Moving
8746-------------------------
8747
8748'beginning-of-line (C-a)'
8749 Move to the start of the current line.
8750
8751'end-of-line (C-e)'
8752 Move to the end of the line.
8753
8754'forward-char (C-f)'
8755 Move forward a character.
8756
8757'backward-char (C-b)'
8758 Move back a character.
8759
8760'forward-word (M-f)'
8761 Move forward to the end of the next word. Words are composed of
8762 letters and digits.
8763
8764'backward-word (M-b)'
8765 Move back to the start of the current or previous word. Words are
8766 composed of letters and digits.
8767
8768'shell-forward-word (M-C-f)'
8769 Move forward to the end of the next word. Words are delimited by
8770 non-quoted shell metacharacters.
8771
8772'shell-backward-word (M-C-b)'
8773 Move back to the start of the current or previous word. Words are
8774 delimited by non-quoted shell metacharacters.
8775
8776'previous-screen-line ()'
8777 Attempt to move point to the same physical screen column on the
8778 previous physical screen line. This will not have the desired
8779 effect if the current Readline line does not take up more than one
8780 physical line or if point is not greater than the length of the
8781 prompt plus the screen width.
8782
8783'next-screen-line ()'
8784 Attempt to move point to the same physical screen column on the
8785 next physical screen line. This will not have the desired effect
8786 if the current Readline line does not take up more than one
8787 physical line or if the length of the current Readline line is not
8788 greater than the length of the prompt plus the screen width.
8789
8790'clear-display (M-C-l)'
8791 Clear the screen and, if possible, the terminal's scrollback
8792 buffer, then redraw the current line, leaving the current line at
8793 the top of the screen.
8794
8795'clear-screen (C-l)'
8796 Clear the screen, then redraw the current line, leaving the current
8797 line at the top of the screen.
8798
8799'redraw-current-line ()'
8800 Refresh the current line. By default, this is unbound.
8801
8802\1f
8803File: bashref.info, Node: Commands For History, Next: Commands For Text, Prev: Commands For Moving, Up: Bindable Readline Commands
8804
88058.4.2 Commands For Manipulating The History
8806-------------------------------------------
8807
8808'accept-line (Newline or Return)'
8809 Accept the line regardless of where the cursor is. If this line is
8810 non-empty, add it to the history list according to the setting of
8811 the 'HISTCONTROL' and 'HISTIGNORE' variables. If this line is a
8812 modified history line, then restore the history line to its
8813 original state.
8814
8815'previous-history (C-p)'
8816 Move 'back' through the history list, fetching the previous
8817 command.
8818
8819'next-history (C-n)'
8820 Move 'forward' through the history list, fetching the next command.
8821
8822'beginning-of-history (M-<)'
8823 Move to the first line in the history.
8824
8825'end-of-history (M->)'
8826 Move to the end of the input history, i.e., the line currently
8827 being entered.
8828
8829'reverse-search-history (C-r)'
8830 Search backward starting at the current line and moving 'up'
8831 through the history as necessary. This is an incremental search.
8832 This command sets the region to the matched text and activates the
8833 mark.
8834
8835'forward-search-history (C-s)'
8836 Search forward starting at the current line and moving 'down'
8837 through the history as necessary. This is an incremental search.
8838 This command sets the region to the matched text and activates the
8839 mark.
8840
8841'non-incremental-reverse-search-history (M-p)'
8842 Search backward starting at the current line and moving 'up'
8843 through the history as necessary using a non-incremental search for
8844 a string supplied by the user. The search string may match
8845 anywhere in a history line.
8846
8847'non-incremental-forward-search-history (M-n)'
8848 Search forward starting at the current line and moving 'down'
8849 through the history as necessary using a non-incremental search for
8850 a string supplied by the user. The search string may match
8851 anywhere in a history line.
8852
8853'history-search-forward ()'
8854 Search forward through the history for the string of characters
8855 between the start of the current line and the point. The search
8856 string must match at the beginning of a history line. This is a
8857 non-incremental search. By default, this command is unbound.
8858
8859'history-search-backward ()'
8860 Search backward through the history for the string of characters
8861 between the start of the current line and the point. The search
8862 string must match at the beginning of a history line. This is a
8863 non-incremental search. By default, this command is unbound.
8864
8865'history-substring-search-forward ()'
8866 Search forward through the history for the string of characters
8867 between the start of the current line and the point. The search
8868 string may match anywhere in a history line. This is a
8869 non-incremental search. By default, this command is unbound.
8870
8871'history-substring-search-backward ()'
8872 Search backward through the history for the string of characters
8873 between the start of the current line and the point. The search
8874 string may match anywhere in a history line. This is a
8875 non-incremental search. By default, this command is unbound.
8876
8877'yank-nth-arg (M-C-y)'
8878 Insert the first argument to the previous command (usually the
8879 second word on the previous line) at point. With an argument N,
8880 insert the Nth word from the previous command (the words in the
8881 previous command begin with word 0). A negative argument inserts
8882 the Nth word from the end of the previous command. Once the
8883 argument N is computed, the argument is extracted as if the '!N'
8884 history expansion had been specified.
8885
8886'yank-last-arg (M-. or M-_)'
8887 Insert last argument to the previous command (the last word of the
8888 previous history entry). With a numeric argument, behave exactly
8889 like 'yank-nth-arg'. Successive calls to 'yank-last-arg' move back
8890 through the history list, inserting the last word (or the word
8891 specified by the argument to the first call) of each line in turn.
8892 Any numeric argument supplied to these successive calls determines
8893 the direction to move through the history. A negative argument
8894 switches the direction through the history (back or forward). The
8895 history expansion facilities are used to extract the last argument,
8896 as if the '!$' history expansion had been specified.
8897
8898'operate-and-get-next (C-o)'
8899 Accept the current line for return to the calling application as if
8900 a newline had been entered, and fetch the next line relative to the
8901 current line from the history for editing. A numeric argument, if
8902 supplied, specifies the history entry to use instead of the current
8903 line.
8904
8905'fetch-history ()'
8906 With a numeric argument, fetch that entry from the history list and
8907 make it the current line. Without an argument, move back to the
8908 first entry in the history list.
8909
8910\1f
8911File: bashref.info, Node: Commands For Text, Next: Commands For Killing, Prev: Commands For History, Up: Bindable Readline Commands
8912
89138.4.3 Commands For Changing Text
8914--------------------------------
8915
8916'end-of-file (usually C-d)'
8917 The character indicating end-of-file as set, for example, by
8918 'stty'. If this character is read when there are no characters on
8919 the line, and point is at the beginning of the line, Readline
8920 interprets it as the end of input and returns EOF.
8921
8922'delete-char (C-d)'
8923 Delete the character at point. If this function is bound to the
8924 same character as the tty EOF character, as 'C-d' commonly is, see
8925 above for the effects.
8926
8927'backward-delete-char (Rubout)'
8928 Delete the character behind the cursor. A numeric argument means
8929 to kill the characters instead of deleting them.
8930
8931'forward-backward-delete-char ()'
8932 Delete the character under the cursor, unless the cursor is at the
8933 end of the line, in which case the character behind the cursor is
8934 deleted. By default, this is not bound to a key.
8935
8936'quoted-insert (C-q or C-v)'
8937 Add the next character typed to the line verbatim. This is how to
8938 insert key sequences like 'C-q', for example.
8939
8940'self-insert (a, b, A, 1, !, ...)'
8941 Insert yourself.
8942
8943'bracketed-paste-begin ()'
8944 This function is intended to be bound to the "bracketed paste"
8945 escape sequence sent by some terminals, and such a binding is
8946 assigned by default. It allows Readline to insert the pasted text
8947 as a single unit without treating each character as if it had been
8948 read from the keyboard. The characters are inserted as if each one
8949 was bound to 'self-insert' instead of executing any editing
8950 commands.
8951
8952 Bracketed paste sets the region (the characters between point and
8953 the mark) to the inserted text. It uses the concept of an _active
8954 mark_: when the mark is active, Readline redisplay uses the
8955 terminal's standout mode to denote the region.
8956
8957'transpose-chars (C-t)'
8958 Drag the character before the cursor forward over the character at
8959 the cursor, moving the cursor forward as well. If the insertion
8960 point is at the end of the line, then this transposes the last two
8961 characters of the line. Negative arguments have no effect.
8962
8963'transpose-words (M-t)'
8964 Drag the word before point past the word after point, moving point
8965 past that word as well. If the insertion point is at the end of
8966 the line, this transposes the last two words on the line.
8967
8968'upcase-word (M-u)'
8969 Uppercase the current (or following) word. With a negative
8970 argument, uppercase the previous word, but do not move the cursor.
8971
8972'downcase-word (M-l)'
8973 Lowercase the current (or following) word. With a negative
8974 argument, lowercase the previous word, but do not move the cursor.
8975
8976'capitalize-word (M-c)'
8977 Capitalize the current (or following) word. With a negative
8978 argument, capitalize the previous word, but do not move the cursor.
8979
8980'overwrite-mode ()'
8981 Toggle overwrite mode. With an explicit positive numeric argument,
8982 switches to overwrite mode. With an explicit non-positive numeric
8983 argument, switches to insert mode. This command affects only
8984 'emacs' mode; 'vi' mode does overwrite differently. Each call to
8985 'readline()' starts in insert mode.
8986
8987 In overwrite mode, characters bound to 'self-insert' replace the
8988 text at point rather than pushing the text to the right.
8989 Characters bound to 'backward-delete-char' replace the character
8990 before point with a space.
8991
8992 By default, this command is unbound.
8993
8994\1f
8995File: bashref.info, Node: Commands For Killing, Next: Numeric Arguments, Prev: Commands For Text, Up: Bindable Readline Commands
8996
89978.4.4 Killing And Yanking
8998-------------------------
8999
9000'kill-line (C-k)'
9001 Kill the text from point to the end of the line. With a negative
9002 numeric argument, kill backward from the cursor to the beginning of
9003 the current line.
9004
9005'backward-kill-line (C-x Rubout)'
9006 Kill backward from the cursor to the beginning of the current line.
9007 With a negative numeric argument, kill forward from the cursor to
9008 the end of the current line.
9009
9010'unix-line-discard (C-u)'
9011 Kill backward from the cursor to the beginning of the current line.
9012
9013'kill-whole-line ()'
9014 Kill all characters on the current line, no matter where point is.
9015 By default, this is unbound.
9016
9017'kill-word (M-d)'
9018 Kill from point to the end of the current word, or if between
9019 words, to the end of the next word. Word boundaries are the same
9020 as 'forward-word'.
9021
9022'backward-kill-word (M-<DEL>)'
9023 Kill the word behind point. Word boundaries are the same as
9024 'backward-word'.
9025
9026'shell-kill-word (M-C-d)'
9027 Kill from point to the end of the current word, or if between
9028 words, to the end of the next word. Word boundaries are the same
9029 as 'shell-forward-word'.
9030
9031'shell-backward-kill-word ()'
9032 Kill the word behind point. Word boundaries are the same as
9033 'shell-backward-word'.
9034
9035'shell-transpose-words (M-C-t)'
9036 Drag the word before point past the word after point, moving point
9037 past that word as well. If the insertion point is at the end of
9038 the line, this transposes the last two words on the line. Word
9039 boundaries are the same as 'shell-forward-word' and
9040 'shell-backward-word'.
9041
9042'unix-word-rubout (C-w)'
9043 Kill the word behind point, using white space as a word boundary.
9044 The killed text is saved on the kill-ring.
9045
9046'unix-filename-rubout ()'
9047 Kill the word behind point, using white space and the slash
9048 character as the word boundaries. The killed text is saved on the
9049 kill-ring.
9050
9051'delete-horizontal-space ()'
9052 Delete all spaces and tabs around point. By default, this is
9053 unbound.
9054
9055'kill-region ()'
9056 Kill the text in the current region. By default, this command is
9057 unbound.
9058
9059'copy-region-as-kill ()'
9060 Copy the text in the region to the kill buffer, so it can be yanked
9061 right away. By default, this command is unbound.
9062
9063'copy-backward-word ()'
9064 Copy the word before point to the kill buffer. The word boundaries
9065 are the same as 'backward-word'. By default, this command is
9066 unbound.
9067
9068'copy-forward-word ()'
9069 Copy the word following point to the kill buffer. The word
9070 boundaries are the same as 'forward-word'. By default, this
9071 command is unbound.
9072
9073'yank (C-y)'
9074 Yank the top of the kill ring into the buffer at point.
9075
9076'yank-pop (M-y)'
9077 Rotate the kill-ring, and yank the new top. You can only do this
9078 if the prior command is 'yank' or 'yank-pop'.
9079
9080\1f
9081File: bashref.info, Node: Numeric Arguments, Next: Commands For Completion, Prev: Commands For Killing, Up: Bindable Readline Commands
9082
90838.4.5 Specifying Numeric Arguments
9084----------------------------------
9085
9086'digit-argument (M-0, M-1, ... M--)'
9087 Add this digit to the argument already accumulating, or start a new
9088 argument. 'M--' starts a negative argument.
9089
9090'universal-argument ()'
9091 This is another way to specify an argument. If this command is
9092 followed by one or more digits, optionally with a leading minus
9093 sign, those digits define the argument. If the command is followed
9094 by digits, executing 'universal-argument' again ends the numeric
9095 argument, but is otherwise ignored. As a special case, if this
9096 command is immediately followed by a character that is neither a
9097 digit nor minus sign, the argument count for the next command is
9098 multiplied by four. The argument count is initially one, so
9099 executing this function the first time makes the argument count
9100 four, a second time makes the argument count sixteen, and so on.
9101 By default, this is not bound to a key.
9102
9103\1f
9104File: bashref.info, Node: Commands For Completion, Next: Keyboard Macros, Prev: Numeric Arguments, Up: Bindable Readline Commands
9105
91068.4.6 Letting Readline Type For You
9107-----------------------------------
9108
9109'complete (<TAB>)'
9110 Attempt to perform completion on the text before point. The actual
9111 completion performed is application-specific. Bash attempts
9112 completion treating the text as a variable (if the text begins with
9113 '$'), username (if the text begins with '~'), hostname (if the text
9114 begins with '@'), or command (including aliases and functions) in
9115 turn. If none of these produces a match, filename completion is
9116 attempted.
9117
9118'possible-completions (M-?)'
9119 List the possible completions of the text before point. When
9120 displaying completions, Readline sets the number of columns used
9121 for display to the value of 'completion-display-width', the value
9122 of the environment variable 'COLUMNS', or the screen width, in that
9123 order.
9124
9125'insert-completions (M-*)'
9126 Insert all completions of the text before point that would have
9127 been generated by 'possible-completions'.
9128
9129'menu-complete ()'
9130 Similar to 'complete', but replaces the word to be completed with a
9131 single match from the list of possible completions. Repeated
9132 execution of 'menu-complete' steps through the list of possible
9133 completions, inserting each match in turn. At the end of the list
9134 of completions, the bell is rung (subject to the setting of
9135 'bell-style') and the original text is restored. An argument of N
9136 moves N positions forward in the list of matches; a negative
9137 argument may be used to move backward through the list. This
9138 command is intended to be bound to <TAB>, but is unbound by
9139 default.
9140
9141'menu-complete-backward ()'
9142 Identical to 'menu-complete', but moves backward through the list
9143 of possible completions, as if 'menu-complete' had been given a
9144 negative argument.
9145
9146'delete-char-or-list ()'
9147 Deletes the character under the cursor if not at the beginning or
9148 end of the line (like 'delete-char'). If at the end of the line,
9149 behaves identically to 'possible-completions'. This command is
9150 unbound by default.
9151
9152'complete-filename (M-/)'
9153 Attempt filename completion on the text before point.
9154
9155'possible-filename-completions (C-x /)'
9156 List the possible completions of the text before point, treating it
9157 as a filename.
9158
9159'complete-username (M-~)'
9160 Attempt completion on the text before point, treating it as a
9161 username.
9162
9163'possible-username-completions (C-x ~)'
9164 List the possible completions of the text before point, treating it
9165 as a username.
9166
9167'complete-variable (M-$)'
9168 Attempt completion on the text before point, treating it as a shell
9169 variable.
9170
9171'possible-variable-completions (C-x $)'
9172 List the possible completions of the text before point, treating it
9173 as a shell variable.
9174
9175'complete-hostname (M-@)'
9176 Attempt completion on the text before point, treating it as a
9177 hostname.
9178
9179'possible-hostname-completions (C-x @)'
9180 List the possible completions of the text before point, treating it
9181 as a hostname.
9182
9183'complete-command (M-!)'
9184 Attempt completion on the text before point, treating it as a
9185 command name. Command completion attempts to match the text
9186 against aliases, reserved words, shell functions, shell builtins,
9187 and finally executable filenames, in that order.
9188
9189'possible-command-completions (C-x !)'
9190 List the possible completions of the text before point, treating it
9191 as a command name.
9192
9193'dynamic-complete-history (M-<TAB>)'
9194 Attempt completion on the text before point, comparing the text
9195 against lines from the history list for possible completion
9196 matches.
9197
9198'dabbrev-expand ()'
9199 Attempt menu completion on the text before point, comparing the
9200 text against lines from the history list for possible completion
9201 matches.
9202
9203'complete-into-braces (M-{)'
9204 Perform filename completion and insert the list of possible
9205 completions enclosed within braces so the list is available to the
9206 shell (*note Brace Expansion::).
9207
9208\1f
9209File: bashref.info, Node: Keyboard Macros, Next: Miscellaneous Commands, Prev: Commands For Completion, Up: Bindable Readline Commands
9210
92118.4.7 Keyboard Macros
9212---------------------
9213
9214'start-kbd-macro (C-x ()'
9215 Begin saving the characters typed into the current keyboard macro.
9216
9217'end-kbd-macro (C-x ))'
9218 Stop saving the characters typed into the current keyboard macro
9219 and save the definition.
9220
9221'call-last-kbd-macro (C-x e)'
9222 Re-execute the last keyboard macro defined, by making the
9223 characters in the macro appear as if typed at the keyboard.
9224
9225'print-last-kbd-macro ()'
9226 Print the last keyboard macro defined in a format suitable for the
9227 INPUTRC file.
9228
9229\1f
9230File: bashref.info, Node: Miscellaneous Commands, Prev: Keyboard Macros, Up: Bindable Readline Commands
9231
92328.4.8 Some Miscellaneous Commands
9233---------------------------------
9234
9235're-read-init-file (C-x C-r)'
9236 Read in the contents of the INPUTRC file, and incorporate any
9237 bindings or variable assignments found there.
9238
9239'abort (C-g)'
9240 Abort the current editing command and ring the terminal's bell
9241 (subject to the setting of 'bell-style').
9242
9243'do-lowercase-version (M-A, M-B, M-X, ...)'
9244 If the metafied character X is upper case, run the command that is
9245 bound to the corresponding metafied lower case character. The
9246 behavior is undefined if X is already lower case.
9247
9248'prefix-meta (<ESC>)'
9249 Metafy the next character typed. This is for keyboards without a
9250 meta key. Typing '<ESC> f' is equivalent to typing 'M-f'.
9251
9252'undo (C-_ or C-x C-u)'
9253 Incremental undo, separately remembered for each line.
9254
9255'revert-line (M-r)'
9256 Undo all changes made to this line. This is like executing the
9257 'undo' command enough times to get back to the beginning.
9258
9259'tilde-expand (M-&)'
9260 Perform tilde expansion on the current word.
9261
9262'set-mark (C-@)'
9263 Set the mark to the point. If a numeric argument is supplied, the
9264 mark is set to that position.
9265
9266'exchange-point-and-mark (C-x C-x)'
9267 Swap the point with the mark. The current cursor position is set
9268 to the saved position, and the old cursor position is saved as the
9269 mark.
9270
9271'character-search (C-])'
9272 A character is read and point is moved to the next occurrence of
9273 that character. A negative argument searches for previous
9274 occurrences.
9275
9276'character-search-backward (M-C-])'
9277 A character is read and point is moved to the previous occurrence
9278 of that character. A negative argument searches for subsequent
9279 occurrences.
9280
9281'skip-csi-sequence ()'
9282 Read enough characters to consume a multi-key sequence such as
9283 those defined for keys like Home and End. Such sequences begin
9284 with a Control Sequence Indicator (CSI), usually ESC-[. If this
9285 sequence is bound to "\e[", keys producing such sequences will have
9286 no effect unless explicitly bound to a Readline command, instead of
9287 inserting stray characters into the editing buffer. This is
9288 unbound by default, but usually bound to ESC-[.
9289
9290'insert-comment (M-#)'
9291 Without a numeric argument, the value of the 'comment-begin'
9292 variable is inserted at the beginning of the current line. If a
9293 numeric argument is supplied, this command acts as a toggle: if the
9294 characters at the beginning of the line do not match the value of
9295 'comment-begin', the value is inserted, otherwise the characters in
9296 'comment-begin' are deleted from the beginning of the line. In
9297 either case, the line is accepted as if a newline had been typed.
9298 The default value of 'comment-begin' causes this command to make
9299 the current line a shell comment. If a numeric argument causes the
9300 comment character to be removed, the line will be executed by the
9301 shell.
9302
9303'dump-functions ()'
9304 Print all of the functions and their key bindings to the Readline
9305 output stream. If a numeric argument is supplied, the output is
9306 formatted in such a way that it can be made part of an INPUTRC
9307 file. This command is unbound by default.
9308
9309'dump-variables ()'
9310 Print all of the settable variables and their values to the
9311 Readline output stream. If a numeric argument is supplied, the
9312 output is formatted in such a way that it can be made part of an
9313 INPUTRC file. This command is unbound by default.
9314
9315'dump-macros ()'
9316 Print all of the Readline key sequences bound to macros and the
9317 strings they output. If a numeric argument is supplied, the output
9318 is formatted in such a way that it can be made part of an INPUTRC
9319 file. This command is unbound by default.
9320
9321'spell-correct-word (C-x s)'
9322 Perform spelling correction on the current word, treating it as a
9323 directory or filename, in the same way as the 'cdspell' shell
9324 option. Word boundaries are the same as those used by
9325 'shell-forward-word'.
9326
9327'glob-complete-word (M-g)'
9328 The word before point is treated as a pattern for pathname
9329 expansion, with an asterisk implicitly appended. This pattern is
9330 used to generate a list of matching file names for possible
9331 completions.
9332
9333'glob-expand-word (C-x *)'
9334 The word before point is treated as a pattern for pathname
9335 expansion, and the list of matching file names is inserted,
9336 replacing the word. If a numeric argument is supplied, a '*' is
9337 appended before pathname expansion.
9338
9339'glob-list-expansions (C-x g)'
9340 The list of expansions that would have been generated by
9341 'glob-expand-word' is displayed, and the line is redrawn. If a
9342 numeric argument is supplied, a '*' is appended before pathname
9343 expansion.
9344
9345'display-shell-version (C-x C-v)'
9346 Display version information about the current instance of Bash.
9347
9348'shell-expand-line (M-C-e)'
9349 Expand the line as the shell does. This performs alias and history
9350 expansion as well as all of the shell word expansions (*note Shell
9351 Expansions::).
9352
9353'history-expand-line (M-^)'
9354 Perform history expansion on the current line.
9355
9356'magic-space ()'
9357 Perform history expansion on the current line and insert a space
9358 (*note History Interaction::).
9359
9360'alias-expand-line ()'
9361 Perform alias expansion on the current line (*note Aliases::).
9362
9363'history-and-alias-expand-line ()'
9364 Perform history and alias expansion on the current line.
9365
9366'insert-last-argument (M-. or M-_)'
9367 A synonym for 'yank-last-arg'.
9368
9369'edit-and-execute-command (C-x C-e)'
9370 Invoke an editor on the current command line, and execute the
9371 result as shell commands. Bash attempts to invoke '$VISUAL',
9372 '$EDITOR', and 'emacs' as the editor, in that order.
9373
9374\1f
9375File: bashref.info, Node: Readline vi Mode, Next: Programmable Completion, Prev: Bindable Readline Commands, Up: Command Line Editing
9376
93778.5 Readline vi Mode
9378====================
9379
9380While the Readline library does not have a full set of 'vi' editing
9381functions, it does contain enough to allow simple editing of the line.
9382The Readline 'vi' mode behaves as specified in the POSIX standard.
9383
9384 In order to switch interactively between 'emacs' and 'vi' editing
9385modes, use the 'set -o emacs' and 'set -o vi' commands (*note The Set
9386Builtin::). The Readline default is 'emacs' mode.
9387
9388 When you enter a line in 'vi' mode, you are already placed in
9389'insertion' mode, as if you had typed an 'i'. Pressing <ESC> switches
9390you into 'command' mode, where you can edit the text of the line with
9391the standard 'vi' movement keys, move to previous history lines with 'k'
9392and subsequent lines with 'j', and so forth.
9393
9394\1f
9395File: bashref.info, Node: Programmable Completion, Next: Programmable Completion Builtins, Prev: Readline vi Mode, Up: Command Line Editing
9396
93978.6 Programmable Completion
9398===========================
9399
9400When word completion is attempted for an argument to a command for which
9401a completion specification (a COMPSPEC) has been defined using the
9402'complete' builtin (*note Programmable Completion Builtins::), the
9403programmable completion facilities are invoked.
9404
9405 First, the command name is identified. If a compspec has been
9406defined for that command, the compspec is used to generate the list of
9407possible completions for the word. If the command word is the empty
9408string (completion attempted at the beginning of an empty line), any
9409compspec defined with the '-E' option to 'complete' is used. If the
9410command word is a full pathname, a compspec for the full pathname is
9411searched for first. If no compspec is found for the full pathname, an
9412attempt is made to find a compspec for the portion following the final
9413slash. If those searches do not result in a compspec, any compspec
9414defined with the '-D' option to 'complete' is used as the default. If
9415there is no default compspec, Bash attempts alias expansion on the
9416command word as a final resort, and attempts to find a compspec for the
9417command word from any successful expansion
9418
9419 Once a compspec has been found, it is used to generate the list of
9420matching words. If a compspec is not found, the default Bash completion
9421described above (*note Commands For Completion::) is performed.
9422
9423 First, the actions specified by the compspec are used. Only matches
9424which are prefixed by the word being completed are returned. When the
9425'-f' or '-d' option is used for filename or directory name completion,
9426the shell variable 'FIGNORE' is used to filter the matches. *Note Bash
9427Variables::, for a description of 'FIGNORE'.
9428
9429 Any completions specified by a filename expansion pattern to the '-G'
9430option are generated next. The words generated by the pattern need not
9431match the word being completed. The 'GLOBIGNORE' shell variable is not
9432used to filter the matches, but the 'FIGNORE' shell variable is used.
9433
9434 Next, the string specified as the argument to the '-W' option is
9435considered. The string is first split using the characters in the 'IFS'
9436special variable as delimiters. Shell quoting is honored within the
9437string, in order to provide a mechanism for the words to contain shell
9438metacharacters or characters in the value of 'IFS'. Each word is then
9439expanded using brace expansion, tilde expansion, parameter and variable
9440expansion, command substitution, and arithmetic expansion, as described
9441above (*note Shell Expansions::). The results are split using the rules
9442described above (*note Word Splitting::). The results of the expansion
9443are prefix-matched against the word being completed, and the matching
9444words become the possible completions.
9445
9446 After these matches have been generated, any shell function or
9447command specified with the '-F' and '-C' options is invoked. When the
9448command or function is invoked, the 'COMP_LINE', 'COMP_POINT',
9449'COMP_KEY', and 'COMP_TYPE' variables are assigned values as described
9450above (*note Bash Variables::). If a shell function is being invoked,
9451the 'COMP_WORDS' and 'COMP_CWORD' variables are also set. When the
9452function or command is invoked, the first argument ($1) is the name of
9453the command whose arguments are being completed, the second argument
9454($2) is the word being completed, and the third argument ($3) is the
9455word preceding the word being completed on the current command line. No
9456filtering of the generated completions against the word being completed
9457is performed; the function or command has complete freedom in generating
9458the matches.
9459
9460 Any function specified with '-F' is invoked first. The function may
9461use any of the shell facilities, including the 'compgen' and 'compopt'
9462builtins described below (*note Programmable Completion Builtins::), to
9463generate the matches. It must put the possible completions in the
9464'COMPREPLY' array variable, one per array element.
9465
9466 Next, any command specified with the '-C' option is invoked in an
9467environment equivalent to command substitution. It should print a list
9468of completions, one per line, to the standard output. Backslash may be
9469used to escape a newline, if necessary.
9470
9471 After all of the possible completions are generated, any filter
9472specified with the '-X' option is applied to the list. The filter is a
9473pattern as used for pathname expansion; a '&' in the pattern is replaced
9474with the text of the word being completed. A literal '&' may be escaped
9475with a backslash; the backslash is removed before attempting a match.
9476Any completion that matches the pattern will be removed from the list.
9477A leading '!' negates the pattern; in this case any completion not
9478matching the pattern will be removed. If the 'nocasematch' shell option
9479(see the description of 'shopt' in *note The Shopt Builtin::) is
9480enabled, the match is performed without regard to the case of alphabetic
9481characters.
9482
9483 Finally, any prefix and suffix specified with the '-P' and '-S'
9484options are added to each member of the completion list, and the result
9485is returned to the Readline completion code as the list of possible
9486completions.
9487
9488 If the previously-applied actions do not generate any matches, and
9489the '-o dirnames' option was supplied to 'complete' when the compspec
9490was defined, directory name completion is attempted.
9491
9492 If the '-o plusdirs' option was supplied to 'complete' when the
9493compspec was defined, directory name completion is attempted and any
9494matches are added to the results of the other actions.
9495
9496 By default, if a compspec is found, whatever it generates is returned
9497to the completion code as the full set of possible completions. The
9498default Bash completions are not attempted, and the Readline default of
9499filename completion is disabled. If the '-o bashdefault' option was
9500supplied to 'complete' when the compspec was defined, the default Bash
9501completions are attempted if the compspec generates no matches. If the
9502'-o default' option was supplied to 'complete' when the compspec was
9503defined, Readline's default completion will be performed if the compspec
9504(and, if attempted, the default Bash completions) generate no matches.
9505
9506 When a compspec indicates that directory name completion is desired,
9507the programmable completion functions force Readline to append a slash
9508to completed names which are symbolic links to directories, subject to
9509the value of the MARK-DIRECTORIES Readline variable, regardless of the
9510setting of the MARK-SYMLINKED-DIRECTORIES Readline variable.
9511
9512 There is some support for dynamically modifying completions. This is
9513most useful when used in combination with a default completion specified
9514with '-D'. It's possible for shell functions executed as completion
9515handlers to indicate that completion should be retried by returning an
9516exit status of 124. If a shell function returns 124, and changes the
9517compspec associated with the command on which completion is being
9518attempted (supplied as the first argument when the function is
9519executed), programmable completion restarts from the beginning, with an
9520attempt to find a new compspec for that command. This allows a set of
9521completions to be built dynamically as completion is attempted, rather
9522than being loaded all at once.
9523
9524 For instance, assuming that there is a library of compspecs, each
9525kept in a file corresponding to the name of the command, the following
9526default completion function would load completions dynamically:
9527
9528 _completion_loader()
9529 {
9530 . "/etc/bash_completion.d/$1.sh" >/dev/null 2>&1 && return 124
9531 }
9532 complete -D -F _completion_loader -o bashdefault -o default
9533
9534\1f
9535File: bashref.info, Node: Programmable Completion Builtins, Next: A Programmable Completion Example, Prev: Programmable Completion, Up: Command Line Editing
9536
95378.7 Programmable Completion Builtins
9538====================================
9539
9540Three builtin commands are available to manipulate the programmable
9541completion facilities: one to specify how the arguments to a particular
9542command are to be completed, and two to modify the completion as it is
9543happening.
9544
9545'compgen'
9546 compgen [OPTION] [WORD]
9547
9548 Generate possible completion matches for WORD according to the
9549 OPTIONs, which may be any option accepted by the 'complete' builtin
9550 with the exception of '-p' and '-r', and write the matches to the
9551 standard output. When using the '-F' or '-C' options, the various
9552 shell variables set by the programmable completion facilities,
9553 while available, will not have useful values.
9554
9555 The matches will be generated in the same way as if the
9556 programmable completion code had generated them directly from a
9557 completion specification with the same flags. If WORD is
9558 specified, only those completions matching WORD will be displayed.
9559
9560 The return value is true unless an invalid option is supplied, or
9561 no matches were generated.
9562
9563'complete'
9564 complete [-abcdefgjksuv] [-o COMP-OPTION] [-DEI] [-A ACTION] [-G GLOBPAT]
9565 [-W WORDLIST] [-F FUNCTION] [-C COMMAND] [-X FILTERPAT]
9566 [-P PREFIX] [-S SUFFIX] NAME [NAME ...]
9567 complete -pr [-DEI] [NAME ...]
9568
9569 Specify how arguments to each NAME should be completed. If the
9570 '-p' option is supplied, or if no options are supplied, existing
9571 completion specifications are printed in a way that allows them to
9572 be reused as input. The '-r' option removes a completion
9573 specification for each NAME, or, if no NAMEs are supplied, all
9574 completion specifications. The '-D' option indicates that other
9575 supplied options and actions should apply to the "default" command
9576 completion; that is, completion attempted on a command for which no
9577 completion has previously been defined. The '-E' option indicates
9578 that other supplied options and actions should apply to "empty"
9579 command completion; that is, completion attempted on a blank line.
9580 The '-I' option indicates that other supplied options and actions
9581 should apply to completion on the initial non-assignment word on
9582 the line, or after a command delimiter such as ';' or '|', which is
9583 usually command name completion. If multiple options are supplied,
9584 the '-D' option takes precedence over '-E', and both take
9585 precedence over '-I'. If any of '-D', '-E', or '-I' are supplied,
9586 any other NAME arguments are ignored; these completions only apply
9587 to the case specified by the option.
9588
9589 The process of applying these completion specifications when word
9590 completion is attempted is described above (*note Programmable
9591 Completion::).
9592
9593 Other options, if specified, have the following meanings. The
9594 arguments to the '-G', '-W', and '-X' options (and, if necessary,
9595 the '-P' and '-S' options) should be quoted to protect them from
9596 expansion before the 'complete' builtin is invoked.
9597
9598 '-o COMP-OPTION'
9599 The COMP-OPTION controls several aspects of the compspec's
9600 behavior beyond the simple generation of completions.
9601 COMP-OPTION may be one of:
9602
9603 'bashdefault'
9604 Perform the rest of the default Bash completions if the
9605 compspec generates no matches.
9606
9607 'default'
9608 Use Readline's default filename completion if the
9609 compspec generates no matches.
9610
9611 'dirnames'
9612 Perform directory name completion if the compspec
9613 generates no matches.
9614
9615 'filenames'
9616 Tell Readline that the compspec generates filenames, so
9617 it can perform any filename-specific processing (like
9618 adding a slash to directory names, quoting special
9619 characters, or suppressing trailing spaces). This option
9620 is intended to be used with shell functions specified
9621 with '-F'.
9622
9623 'noquote'
9624 Tell Readline not to quote the completed words if they
9625 are filenames (quoting filenames is the default).
9626
9627 'nosort'
9628 Tell Readline not to sort the list of possible
9629 completions alphabetically.
9630
9631 'nospace'
9632 Tell Readline not to append a space (the default) to
9633 words completed at the end of the line.
9634
9635 'plusdirs'
9636 After any matches defined by the compspec are generated,
9637 directory name completion is attempted and any matches
9638 are added to the results of the other actions.
9639
9640 '-A ACTION'
9641 The ACTION may be one of the following to generate a list of
9642 possible completions:
9643
9644 'alias'
9645 Alias names. May also be specified as '-a'.
9646
9647 'arrayvar'
9648 Array variable names.
9649
9650 'binding'
9651 Readline key binding names (*note Bindable Readline
9652 Commands::).
9653
9654 'builtin'
9655 Names of shell builtin commands. May also be specified
9656 as '-b'.
9657
9658 'command'
9659 Command names. May also be specified as '-c'.
9660
9661 'directory'
9662 Directory names. May also be specified as '-d'.
9663
9664 'disabled'
9665 Names of disabled shell builtins.
9666
9667 'enabled'
9668 Names of enabled shell builtins.
9669
9670 'export'
9671 Names of exported shell variables. May also be specified
9672 as '-e'.
9673
9674 'file'
9675 File names. May also be specified as '-f'.
9676
9677 'function'
9678 Names of shell functions.
9679
9680 'group'
9681 Group names. May also be specified as '-g'.
9682
9683 'helptopic'
9684 Help topics as accepted by the 'help' builtin (*note Bash
9685 Builtins::).
9686
9687 'hostname'
9688 Hostnames, as taken from the file specified by the
9689 'HOSTFILE' shell variable (*note Bash Variables::).
9690
9691 'job'
9692 Job names, if job control is active. May also be
9693 specified as '-j'.
9694
9695 'keyword'
9696 Shell reserved words. May also be specified as '-k'.
9697
9698 'running'
9699 Names of running jobs, if job control is active.
9700
9701 'service'
9702 Service names. May also be specified as '-s'.
9703
9704 'setopt'
9705 Valid arguments for the '-o' option to the 'set' builtin
9706 (*note The Set Builtin::).
9707
9708 'shopt'
9709 Shell option names as accepted by the 'shopt' builtin
9710 (*note Bash Builtins::).
9711
9712 'signal'
9713 Signal names.
9714
9715 'stopped'
9716 Names of stopped jobs, if job control is active.
9717
9718 'user'
9719 User names. May also be specified as '-u'.
9720
9721 'variable'
9722 Names of all shell variables. May also be specified as
9723 '-v'.
9724
9725 '-C COMMAND'
9726 COMMAND is executed in a subshell environment, and its output
9727 is used as the possible completions. Arguments are passed as
9728 with the '-F' option.
9729
9730 '-F FUNCTION'
9731 The shell function FUNCTION is executed in the current shell
9732 environment. When it is executed, $1 is the name of the
9733 command whose arguments are being completed, $2 is the word
9734 being completed, and $3 is the word preceding the word being
9735 completed, as described above (*note Programmable
9736 Completion::). When it finishes, the possible completions are
9737 retrieved from the value of the 'COMPREPLY' array variable.
9738
9739 '-G GLOBPAT'
9740 The filename expansion pattern GLOBPAT is expanded to generate
9741 the possible completions.
9742
9743 '-P PREFIX'
9744 PREFIX is added at the beginning of each possible completion
9745 after all other options have been applied.
9746
9747 '-S SUFFIX'
9748 SUFFIX is appended to each possible completion after all other
9749 options have been applied.
9750
9751 '-W WORDLIST'
9752 The WORDLIST is split using the characters in the 'IFS'
9753 special variable as delimiters, and each resultant word is
9754 expanded. The possible completions are the members of the
9755 resultant list which match the word being completed.
9756
9757 '-X FILTERPAT'
9758 FILTERPAT is a pattern as used for filename expansion. It is
9759 applied to the list of possible completions generated by the
9760 preceding options and arguments, and each completion matching
9761 FILTERPAT is removed from the list. A leading '!' in
9762 FILTERPAT negates the pattern; in this case, any completion
9763 not matching FILTERPAT is removed.
9764
9765 The return value is true unless an invalid option is supplied, an
9766 option other than '-p' or '-r' is supplied without a NAME argument,
9767 an attempt is made to remove a completion specification for a NAME
9768 for which no specification exists, or an error occurs adding a
9769 completion specification.
9770
9771'compopt'
9772 compopt [-o OPTION] [-DEI] [+o OPTION] [NAME]
9773 Modify completion options for each NAME according to the OPTIONs,
9774 or for the currently-executing completion if no NAMEs are supplied.
9775 If no OPTIONs are given, display the completion options for each
9776 NAME or the current completion. The possible values of OPTION are
9777 those valid for the 'complete' builtin described above. The '-D'
9778 option indicates that other supplied options should apply to the
9779 "default" command completion; that is, completion attempted on a
9780 command for which no completion has previously been defined. The
9781 '-E' option indicates that other supplied options should apply to
9782 "empty" command completion; that is, completion attempted on a
9783 blank line. The '-I' option indicates that other supplied options
9784 should apply to completion on the initial non-assignment word on
9785 the line, or after a command delimiter such as ';' or '|', which is
9786 usually command name completion.
9787
9788 If multiple options are supplied, the '-D' option takes precedence
9789 over '-E', and both take precedence over '-I'
9790
9791 The return value is true unless an invalid option is supplied, an
9792 attempt is made to modify the options for a NAME for which no
9793 completion specification exists, or an output error occurs.
9794
9795\1f
9796File: bashref.info, Node: A Programmable Completion Example, Prev: Programmable Completion Builtins, Up: Command Line Editing
9797
97988.8 A Programmable Completion Example
9799=====================================
9800
9801The most common way to obtain additional completion functionality beyond
9802the default actions 'complete' and 'compgen' provide is to use a shell
9803function and bind it to a particular command using 'complete -F'.
9804
9805 The following function provides completions for the 'cd' builtin. It
9806is a reasonably good example of what shell functions must do when used
9807for completion. This function uses the word passed as '$2' to determine
9808the directory name to complete. You can also use the 'COMP_WORDS' array
9809variable; the current word is indexed by the 'COMP_CWORD' variable.
9810
9811 The function relies on the 'complete' and 'compgen' builtins to do
9812much of the work, adding only the things that the Bash 'cd' does beyond
9813accepting basic directory names: tilde expansion (*note Tilde
9814Expansion::), searching directories in $CDPATH, which is described above
9815(*note Bourne Shell Builtins::), and basic support for the 'cdable_vars'
9816shell option (*note The Shopt Builtin::). '_comp_cd' modifies the value
9817of IFS so that it contains only a newline to accommodate file names
9818containing spaces and tabs - 'compgen' prints the possible completions
9819it generates one per line.
9820
9821 Possible completions go into the COMPREPLY array variable, one
9822completion per array element. The programmable completion system
9823retrieves the completions from there when the function returns.
9824
9825 # A completion function for the cd builtin
9826 # based on the cd completion function from the bash_completion package
9827 _comp_cd()
9828 {
9829 local IFS=$' \t\n' # normalize IFS
9830 local cur _skipdot _cdpath
9831 local i j k
9832
9833 # Tilde expansion, which also expands tilde to full pathname
9834 case "$2" in
9835 \~*) eval cur="$2" ;;
9836 *) cur=$2 ;;
9837 esac
9838
9839 # no cdpath or absolute pathname -- straight directory completion
9840 if [[ -z "${CDPATH:-}" ]] || [[ "$cur" == @(./*|../*|/*) ]]; then
9841 # compgen prints paths one per line; could also use while loop
9842 IFS=$'\n'
9843 COMPREPLY=( $(compgen -d -- "$cur") )
9844 IFS=$' \t\n'
9845 # CDPATH+directories in the current directory if not in CDPATH
9846 else
9847 IFS=$'\n'
9848 _skipdot=false
9849 # preprocess CDPATH to convert null directory names to .
9850 _cdpath=${CDPATH/#:/.:}
9851 _cdpath=${_cdpath//::/:.:}
9852 _cdpath=${_cdpath/%:/:.}
9853 for i in ${_cdpath//:/$'\n'}; do
9854 if [[ $i -ef . ]]; then _skipdot=true; fi
9855 k="${#COMPREPLY[@]}"
9856 for j in $( compgen -d -- "$i/$cur" ); do
9857 COMPREPLY[k++]=${j#$i/} # cut off directory
9858 done
9859 done
9860 $_skipdot || COMPREPLY+=( $(compgen -d -- "$cur") )
9861 IFS=$' \t\n'
9862 fi
9863
9864 # variable names if appropriate shell option set and no completions
9865 if shopt -q cdable_vars && [[ ${#COMPREPLY[@]} -eq 0 ]]; then
9866 COMPREPLY=( $(compgen -v -- "$cur") )
9867 fi
9868
9869 return 0
9870 }
9871
9872 We install the completion function using the '-F' option to
9873'complete':
9874
9875 # Tell readline to quote appropriate and append slashes to directories;
9876 # use the bash default completion for other arguments
9877 complete -o filenames -o nospace -o bashdefault -F _comp_cd cd
9878
9879Since we'd like Bash and Readline to take care of some of the other
9880details for us, we use several other options to tell Bash and Readline
9881what to do. The '-o filenames' option tells Readline that the possible
9882completions should be treated as filenames, and quoted appropriately.
9883That option will also cause Readline to append a slash to filenames it
9884can determine are directories (which is why we might want to extend
9885'_comp_cd' to append a slash if we're using directories found via
9886CDPATH: Readline can't tell those completions are directories). The '-o
9887nospace' option tells Readline to not append a space character to the
9888directory name, in case we want to append to it. The '-o bashdefault'
9889option brings in the rest of the "Bash default" completions - possible
9890completions that Bash adds to the default Readline set. These include
9891things like command name completion, variable completion for words
9892beginning with '$' or '${', completions containing pathname expansion
9893patterns (*note Filename Expansion::), and so on.
9894
9895 Once installed using 'complete', '_comp_cd' will be called every time
9896we attempt word completion for a 'cd' command.
9897
9898 Many more examples - an extensive collection of completions for most
9899of the common GNU, Unix, and Linux commands - are available as part of
9900the bash_completion project. This is installed by default on many
9901GNU/Linux distributions. Originally written by Ian Macdonald, the
9902project now lives at <https://github.com/scop/bash-completion/>. There
9903are ports for other systems such as Solaris and Mac OS X.
9904
9905 An older version of the bash_completion package is distributed with
9906bash in the 'examples/complete' subdirectory.
9907
9908\1f
9909File: bashref.info, Node: Using History Interactively, Next: Installing Bash, Prev: Command Line Editing, Up: Top
9910
99119 Using History Interactively
9912*****************************
9913
9914This chapter describes how to use the GNU History Library interactively,
9915from a user's standpoint. It should be considered a user's guide. For
9916information on using the GNU History Library in other programs, see the
9917GNU Readline Library Manual.
9918
9919* Menu:
9920
9921* Bash History Facilities:: How Bash lets you manipulate your command
9922 history.
9923* Bash History Builtins:: The Bash builtin commands that manipulate
9924 the command history.
9925* History Interaction:: What it feels like using History as a user.
9926
9927\1f
9928File: bashref.info, Node: Bash History Facilities, Next: Bash History Builtins, Up: Using History Interactively
9929
99309.1 Bash History Facilities
9931===========================
9932
9933When the '-o history' option to the 'set' builtin is enabled (*note The
9934Set Builtin::), the shell provides access to the "command history", the
9935list of commands previously typed. The value of the 'HISTSIZE' shell
9936variable is used as the number of commands to save in a history list.
9937The text of the last '$HISTSIZE' commands (default 500) is saved. The
9938shell stores each command in the history list prior to parameter and
9939variable expansion but after history expansion is performed, subject to
9940the values of the shell variables 'HISTIGNORE' and 'HISTCONTROL'.
9941
9942 When the shell starts up, the history is initialized from the file
9943named by the 'HISTFILE' variable (default '~/.bash_history'). The file
9944named by the value of 'HISTFILE' is truncated, if necessary, to contain
9945no more than the number of lines specified by the value of the
9946'HISTFILESIZE' variable. When a shell with history enabled exits, the
9947last '$HISTSIZE' lines are copied from the history list to the file
9948named by '$HISTFILE'. If the 'histappend' shell option is set (*note
9949Bash Builtins::), the lines are appended to the history file, otherwise
9950the history file is overwritten. If 'HISTFILE' is unset, or if the
9951history file is unwritable, the history is not saved. After saving the
9952history, the history file is truncated to contain no more than
9953'$HISTFILESIZE' lines. If 'HISTFILESIZE' is unset, or set to null, a
9954non-numeric value, or a numeric value less than zero, the history file
9955is not truncated.
9956
9957 If the 'HISTTIMEFORMAT' is set, the time stamp information associated
9958with each history entry is written to the history file, marked with the
9959history comment character. When the history file is read, lines
9960beginning with the history comment character followed immediately by a
9961digit are interpreted as timestamps for the following history entry.
9962
9963 The builtin command 'fc' may be used to list or edit and re-execute a
9964portion of the history list. The 'history' builtin may be used to
9965display or modify the history list and manipulate the history file.
9966When using command-line editing, search commands are available in each
9967editing mode that provide access to the history list (*note Commands For
9968History::).
9969
9970 The shell allows control over which commands are saved on the history
9971list. The 'HISTCONTROL' and 'HISTIGNORE' variables may be set to cause
9972the shell to save only a subset of the commands entered. The 'cmdhist'
9973shell option, if enabled, causes the shell to attempt to save each line
9974of a multi-line command in the same history entry, adding semicolons
9975where necessary to preserve syntactic correctness. The 'lithist' shell
9976option causes the shell to save the command with embedded newlines
9977instead of semicolons. The 'shopt' builtin is used to set these
9978options. *Note The Shopt Builtin::, for a description of 'shopt'.
9979
9980\1f
9981File: bashref.info, Node: Bash History Builtins, Next: History Interaction, Prev: Bash History Facilities, Up: Using History Interactively
9982
99839.2 Bash History Builtins
9984=========================
9985
9986Bash provides two builtin commands which manipulate the history list and
9987history file.
9988
9989'fc'
9990 fc [-e ENAME] [-lnr] [FIRST] [LAST]
9991 fc -s [PAT=REP] [COMMAND]
9992
9993 The first form selects a range of commands from FIRST to LAST from
9994 the history list and displays or edits and re-executes them. Both
9995 FIRST and LAST may be specified as a string (to locate the most
9996 recent command beginning with that string) or as a number (an index
9997 into the history list, where a negative number is used as an offset
9998 from the current command number).
9999
10000 When listing, a FIRST or LAST of 0 is equivalent to -1 and -0 is
10001 equivalent to the current command (usually the 'fc' command);
10002 otherwise 0 is equivalent to -1 and -0 is invalid.
10003
10004 If LAST is not specified, it is set to FIRST. If FIRST is not
10005 specified, it is set to the previous command for editing and -16
10006 for listing. If the '-l' flag is given, the commands are listed on
10007 standard output. The '-n' flag suppresses the command numbers when
10008 listing. The '-r' flag reverses the order of the listing.
10009 Otherwise, the editor given by ENAME is invoked on a file
10010 containing those commands. If ENAME is not given, the value of the
10011 following variable expansion is used: '${FCEDIT:-${EDITOR:-vi}}'.
10012 This says to use the value of the 'FCEDIT' variable if set, or the
10013 value of the 'EDITOR' variable if that is set, or 'vi' if neither
10014 is set. When editing is complete, the edited commands are echoed
10015 and executed.
10016
10017 In the second form, COMMAND is re-executed after each instance of
10018 PAT in the selected command is replaced by REP. COMMAND is
10019 interpreted the same as FIRST above.
10020
10021 A useful alias to use with the 'fc' command is 'r='fc -s'', so that
10022 typing 'r cc' runs the last command beginning with 'cc' and typing
10023 'r' re-executes the last command (*note Aliases::).
10024
10025'history'
10026 history [N]
10027 history -c
10028 history -d OFFSET
10029 history -d START-END
10030 history [-anrw] [FILENAME]
10031 history -ps ARG
10032
10033 With no options, display the history list with line numbers. Lines
10034 prefixed with a '*' have been modified. An argument of N lists
10035 only the last N lines. If the shell variable 'HISTTIMEFORMAT' is
10036 set and not null, it is used as a format string for STRFTIME to
10037 display the time stamp associated with each displayed history
10038 entry. No intervening blank is printed between the formatted time
10039 stamp and the history line.
10040
10041 Options, if supplied, have the following meanings:
10042
10043 '-c'
10044 Clear the history list. This may be combined with the other
10045 options to replace the history list completely.
10046
10047 '-d OFFSET'
10048 Delete the history entry at position OFFSET. If OFFSET is
10049 positive, it should be specified as it appears when the
10050 history is displayed. If OFFSET is negative, it is
10051 interpreted as relative to one greater than the last history
10052 position, so negative indices count back from the end of the
10053 history, and an index of '-1' refers to the current 'history
10054 -d' command.
10055
10056 '-d START-END'
10057 Delete the range of history entries between positions START
10058 and END, inclusive. Positive and negative values for START
10059 and END are interpreted as described above.
10060
10061 '-a'
10062 Append the new history lines to the history file. These are
10063 history lines entered since the beginning of the current Bash
10064 session, but not already appended to the history file.
10065
10066 '-n'
10067 Append the history lines not already read from the history
10068 file to the current history list. These are lines appended to
10069 the history file since the beginning of the current Bash
10070 session.
10071
10072 '-r'
10073 Read the history file and append its contents to the history
10074 list.
10075
10076 '-w'
10077 Write out the current history list to the history file.
10078
10079 '-p'
10080 Perform history substitution on the ARGs and display the
10081 result on the standard output, without storing the results in
10082 the history list.
10083
10084 '-s'
10085 The ARGs are added to the end of the history list as a single
10086 entry.
10087
10088 If a FILENAME argument is supplied when any of the '-w', '-r',
10089 '-a', or '-n' options is used, Bash uses FILENAME as the history
10090 file. If not, then the value of the 'HISTFILE' variable is used.
10091
10092 The return value is 0 unless an invalid option is encountered, an
10093 error occurs while reading or writing the history file, an invalid
10094 OFFSET or range is supplied as an argument to '-d', or the history
10095 expansion supplied as an argument to '-p' fails.
10096
10097\1f
10098File: bashref.info, Node: History Interaction, Prev: Bash History Builtins, Up: Using History Interactively
10099
101009.3 History Expansion
10101=====================
10102
10103The History library provides a history expansion feature that is similar
10104to the history expansion provided by 'csh'. This section describes the
10105syntax used to manipulate the history information.
10106
10107 History expansions introduce words from the history list into the
10108input stream, making it easy to repeat commands, insert the arguments to
10109a previous command into the current input line, or fix errors in
10110previous commands quickly.
10111
10112 History expansion is performed immediately after a complete line is
10113read, before the shell breaks it into words, and is performed on each
10114line individually. Bash attempts to inform the history expansion
10115functions about quoting still in effect from previous lines.
10116
10117 History expansion takes place in two parts. The first is to
10118determine which line from the history list should be used during
10119substitution. The second is to select portions of that line for
10120inclusion into the current one. The line selected from the history is
10121called the "event", and the portions of that line that are acted upon
10122are called "words". Various "modifiers" are available to manipulate the
10123selected words. The line is broken into words in the same fashion that
10124Bash does, so that several words surrounded by quotes are considered one
10125word. History expansions are introduced by the appearance of the
10126history expansion character, which is '!' by default.
10127
10128 History expansion implements shell-like quoting conventions: a
10129backslash can be used to remove the special handling for the next
10130character; single quotes enclose verbatim sequences of characters, and
10131can be used to inhibit history expansion; and characters enclosed within
10132double quotes may be subject to history expansion, since backslash can
10133escape the history expansion character, but single quotes may not, since
10134they are not treated specially within double quotes.
10135
10136 When using the shell, only '\' and ''' may be used to escape the
10137history expansion character, but the history expansion character is also
10138treated as quoted if it immediately precedes the closing double quote in
10139a double-quoted string.
10140
10141 Several shell options settable with the 'shopt' builtin (*note The
10142Shopt Builtin::) may be used to tailor the behavior of history
10143expansion. If the 'histverify' shell option is enabled, and Readline is
10144being used, history substitutions are not immediately passed to the
10145shell parser. Instead, the expanded line is reloaded into the Readline
10146editing buffer for further modification. If Readline is being used, and
10147the 'histreedit' shell option is enabled, a failed history expansion
10148will be reloaded into the Readline editing buffer for correction. The
10149'-p' option to the 'history' builtin command may be used to see what a
10150history expansion will do before using it. The '-s' option to the
10151'history' builtin may be used to add commands to the end of the history
10152list without actually executing them, so that they are available for
10153subsequent recall. This is most useful in conjunction with Readline.
10154
10155 The shell allows control of the various characters used by the
10156history expansion mechanism with the 'histchars' variable, as explained
10157above (*note Bash Variables::). The shell uses the history comment
10158character to mark history timestamps when writing the history file.
10159
10160* Menu:
10161
10162* Event Designators:: How to specify which history line to use.
10163* Word Designators:: Specifying which words are of interest.
10164* Modifiers:: Modifying the results of substitution.
10165
10166\1f
10167File: bashref.info, Node: Event Designators, Next: Word Designators, Up: History Interaction
10168
101699.3.1 Event Designators
10170-----------------------
10171
10172An event designator is a reference to a command line entry in the
10173history list. Unless the reference is absolute, events are relative to
10174the current position in the history list.
10175
10176'!'
10177 Start a history substitution, except when followed by a space, tab,
10178 the end of the line, '=' or '(' (when the 'extglob' shell option is
10179 enabled using the 'shopt' builtin).
10180
10181'!N'
10182 Refer to command line N.
10183
10184'!-N'
10185 Refer to the command N lines back.
10186
10187'!!'
10188 Refer to the previous command. This is a synonym for '!-1'.
10189
10190'!STRING'
10191 Refer to the most recent command preceding the current position in
10192 the history list starting with STRING.
10193
10194'!?STRING[?]'
10195 Refer to the most recent command preceding the current position in
10196 the history list containing STRING. The trailing '?' may be
10197 omitted if the STRING is followed immediately by a newline. If
10198 STRING is missing, the string from the most recent search is used;
10199 it is an error if there is no previous search string.
10200
10201'^STRING1^STRING2^'
10202 Quick Substitution. Repeat the last command, replacing STRING1
10203 with STRING2. Equivalent to '!!:s^STRING1^STRING2^'.
10204
10205'!#'
10206 The entire command line typed so far.
10207
10208\1f
10209File: bashref.info, Node: Word Designators, Next: Modifiers, Prev: Event Designators, Up: History Interaction
10210
102119.3.2 Word Designators
10212----------------------
10213
10214Word designators are used to select desired words from the event. A ':'
10215separates the event specification from the word designator. It may be
10216omitted if the word designator begins with a '^', '$', '*', '-', or '%'.
10217Words are numbered from the beginning of the line, with the first word
10218being denoted by 0 (zero). Words are inserted into the current line
10219separated by single spaces.
10220
10221 For example,
10222
10223'!!'
10224 designates the preceding command. When you type this, the
10225 preceding command is repeated in toto.
10226
10227'!!:$'
10228 designates the last argument of the preceding command. This may be
10229 shortened to '!$'.
10230
10231'!fi:2'
10232 designates the second argument of the most recent command starting
10233 with the letters 'fi'.
10234
10235 Here are the word designators:
10236
10237'0 (zero)'
10238 The '0'th word. For many applications, this is the command word.
10239
10240'N'
10241 The Nth word.
10242
10243'^'
10244 The first argument; that is, word 1.
10245
10246'$'
10247 The last argument.
10248
10249'%'
10250 The first word matched by the most recent '?STRING?' search, if the
10251 search string begins with a character that is part of a word.
10252
10253'X-Y'
10254 A range of words; '-Y' abbreviates '0-Y'.
10255
10256'*'
10257 All of the words, except the '0'th. This is a synonym for '1-$'.
10258 It is not an error to use '*' if there is just one word in the
10259 event; the empty string is returned in that case.
10260
10261'X*'
10262 Abbreviates 'X-$'
10263
10264'X-'
10265 Abbreviates 'X-$' like 'X*', but omits the last word. If 'x' is
10266 missing, it defaults to 0.
10267
10268 If a word designator is supplied without an event specification, the
10269previous command is used as the event.
10270
10271\1f
10272File: bashref.info, Node: Modifiers, Prev: Word Designators, Up: History Interaction
10273
102749.3.3 Modifiers
10275---------------
10276
10277After the optional word designator, you can add a sequence of one or
10278more of the following modifiers, each preceded by a ':'. These modify,
10279or edit, the word or words selected from the history event.
10280
10281'h'
10282 Remove a trailing pathname component, leaving only the head.
10283
10284't'
10285 Remove all leading pathname components, leaving the tail.
10286
10287'r'
10288 Remove a trailing suffix of the form '.SUFFIX', leaving the
10289 basename.
10290
10291'e'
10292 Remove all but the trailing suffix.
10293
10294'p'
10295 Print the new command but do not execute it.
10296
10297'q'
10298 Quote the substituted words, escaping further substitutions.
10299
10300'x'
10301 Quote the substituted words as with 'q', but break into words at
10302 spaces, tabs, and newlines. The 'q' and 'x' modifiers are mutually
10303 exclusive; the last one supplied is used.
10304
10305's/OLD/NEW/'
10306 Substitute NEW for the first occurrence of OLD in the event line.
10307 Any character may be used as the delimiter in place of '/'. The
10308 delimiter may be quoted in OLD and NEW with a single backslash. If
10309 '&' appears in NEW, it is replaced by OLD. A single backslash will
10310 quote the '&'. If OLD is null, it is set to the last OLD
10311 substituted, or, if no previous history substitutions took place,
10312 the last STRING in a !?STRING'[?]' search. If NEW is null, each
10313 matching OLD is deleted. The final delimiter is optional if it is
10314 the last character on the input line.
10315
10316'&'
10317 Repeat the previous substitution.
10318
10319'g'
10320'a'
10321 Cause changes to be applied over the entire event line. Used in
10322 conjunction with 's', as in 'gs/OLD/NEW/', or with '&'.
10323
10324'G'
10325 Apply the following 's' or '&' modifier once to each word in the
10326 event.
10327
10328\1f
10329File: bashref.info, Node: Installing Bash, Next: Reporting Bugs, Prev: Using History Interactively, Up: Top
10330
1033110 Installing Bash
10332******************
10333
10334This chapter provides basic instructions for installing Bash on the
10335various supported platforms. The distribution supports the GNU
10336operating systems, nearly every version of Unix, and several non-Unix
10337systems such as BeOS and Interix. Other independent ports exist for
10338MS-DOS, OS/2, and Windows platforms.
10339
10340* Menu:
10341
10342* Basic Installation:: Installation instructions.
10343* Compilers and Options:: How to set special options for various
10344 systems.
10345* Compiling For Multiple Architectures:: How to compile Bash for more
10346 than one kind of system from
10347 the same source tree.
10348* Installation Names:: How to set the various paths used by the installation.
10349* Specifying the System Type:: How to configure Bash for a particular system.
10350* Sharing Defaults:: How to share default configuration values among GNU
10351 programs.
10352* Operation Controls:: Options recognized by the configuration program.
10353* Optional Features:: How to enable and disable optional features when
10354 building Bash.
10355
10356\1f
10357File: bashref.info, Node: Basic Installation, Next: Compilers and Options, Up: Installing Bash
10358
1035910.1 Basic Installation
10360=======================
10361
10362These are installation instructions for Bash.
10363
10364 The simplest way to compile Bash is:
10365
10366 1. 'cd' to the directory containing the source code and type
10367 './configure' to configure Bash for your system. If you're using
10368 'csh' on an old version of System V, you might need to type 'sh
10369 ./configure' instead to prevent 'csh' from trying to execute
10370 'configure' itself.
10371
10372 Running 'configure' takes some time. While running, it prints
10373 messages telling which features it is checking for.
10374
10375 2. Type 'make' to compile Bash and build the 'bashbug' bug reporting
10376 script.
10377
10378 3. Optionally, type 'make tests' to run the Bash test suite.
10379
10380 4. Type 'make install' to install 'bash' and 'bashbug'. This will
10381 also install the manual pages and Info file, message translation
10382 files, some supplemental documentation, a number of example
10383 loadable builtin commands, and a set of header files for developing
10384 loadable builtins. You may need additional privileges to install
10385 'bash' to your desired destination, so 'sudo make install' might be
10386 required. More information about controlling the locations where
10387 'bash' and other files are installed is below (*note Installation
10388 Names::).
10389
10390 The 'configure' shell script attempts to guess correct values for
10391various system-dependent variables used during compilation. It uses
10392those values to create a 'Makefile' in each directory of the package
10393(the top directory, the 'builtins', 'doc', 'po', and 'support'
10394directories, each directory under 'lib', and several others). It also
10395creates a 'config.h' file containing system-dependent definitions.
10396Finally, it creates a shell script named 'config.status' that you can
10397run in the future to recreate the current configuration, a file
10398'config.cache' that saves the results of its tests to speed up
10399reconfiguring, and a file 'config.log' containing compiler output
10400(useful mainly for debugging 'configure'). If at some point
10401'config.cache' contains results you don't want to keep, you may remove
10402or edit it.
10403
10404 To find out more about the options and arguments that the 'configure'
10405script understands, type
10406
10407 bash-4.2$ ./configure --help
10408
10409at the Bash prompt in your Bash source directory.
10410
10411 If you want to build Bash in a directory separate from the source
10412directory - to build for multiple architectures, for example - just use
10413the full path to the configure script. The following commands will
10414build bash in a directory under '/usr/local/build' from the source code
10415in '/usr/local/src/bash-4.4':
10416
10417 mkdir /usr/local/build/bash-4.4
10418 cd /usr/local/build/bash-4.4
10419 bash /usr/local/src/bash-4.4/configure
10420 make
10421
10422 See *note Compiling For Multiple Architectures:: for more information
10423about building in a directory separate from the source.
10424
10425 If you need to do unusual things to compile Bash, please try to
10426figure out how 'configure' could check whether or not to do them, and
10427mail diffs or instructions to <bash-maintainers@gnu.org> so they can be
10428considered for the next release.
10429
10430 The file 'configure.ac' is used to create 'configure' by a program
10431called Autoconf. You only need 'configure.ac' if you want to change it
10432or regenerate 'configure' using a newer version of Autoconf. If you do
10433this, make sure you are using Autoconf version 2.69 or newer.
10434
10435 You can remove the program binaries and object files from the source
10436code directory by typing 'make clean'. To also remove the files that
10437'configure' created (so you can compile Bash for a different kind of
10438computer), type 'make distclean'.
10439
10440\1f
10441File: bashref.info, Node: Compilers and Options, Next: Compiling For Multiple Architectures, Prev: Basic Installation, Up: Installing Bash
10442
1044310.2 Compilers and Options
10444==========================
10445
10446Some systems require unusual options for compilation or linking that the
10447'configure' script does not know about. You can give 'configure'
10448initial values for variables by setting them in the environment. Using
10449a Bourne-compatible shell, you can do that on the command line like
10450this:
10451
10452 CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
10453
10454 On systems that have the 'env' program, you can do it like this:
10455
10456 env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
10457
10458 The configuration process uses GCC to build Bash if it is available.
10459
10460\1f
10461File: bashref.info, Node: Compiling For Multiple Architectures, Next: Installation Names, Prev: Compilers and Options, Up: Installing Bash
10462
1046310.3 Compiling For Multiple Architectures
10464=========================================
10465
10466You can compile Bash for more than one kind of computer at the same
10467time, by placing the object files for each architecture in their own
10468directory. To do this, you must use a version of 'make' that supports
10469the 'VPATH' variable, such as GNU 'make'. 'cd' to the directory where
10470you want the object files and executables to go and run the 'configure'
10471script from the source directory (*note Basic Installation::). You may
10472need to supply the '--srcdir=PATH' argument to tell 'configure' where
10473the source files are. 'configure' automatically checks for the source
10474code in the directory that 'configure' is in and in '..'.
10475
10476 If you have to use a 'make' that does not support the 'VPATH'
10477variable, you can compile Bash for one architecture at a time in the
10478source code directory. After you have installed Bash for one
10479architecture, use 'make distclean' before reconfiguring for another
10480architecture.
10481
10482 Alternatively, if your system supports symbolic links, you can use
10483the 'support/mkclone' script to create a build tree which has symbolic
10484links back to each file in the source directory. Here's an example that
10485creates a build directory in the current directory from a source
10486directory '/usr/gnu/src/bash-2.0':
10487
10488 bash /usr/gnu/src/bash-2.0/support/mkclone -s /usr/gnu/src/bash-2.0 .
10489
10490The 'mkclone' script requires Bash, so you must have already built Bash
10491for at least one architecture before you can create build directories
10492for other architectures.
10493
10494\1f
10495File: bashref.info, Node: Installation Names, Next: Specifying the System Type, Prev: Compiling For Multiple Architectures, Up: Installing Bash
10496
1049710.4 Installation Names
10498=======================
10499
10500By default, 'make install' will install into '/usr/local/bin',
10501'/usr/local/man', etc.; that is, the "installation prefix" defaults to
10502'/usr/local'. You can specify an installation prefix other than
10503'/usr/local' by giving 'configure' the option '--prefix=PATH', or by
10504specifying a value for the 'prefix' 'make' variable when running 'make
10505install' (e.g., 'make install prefix=PATH'). The 'prefix' variable
10506provides a default for 'exec_prefix' and other variables used when
10507installing bash.
10508
10509 You can specify separate installation prefixes for
10510architecture-specific files and architecture-independent files. If you
10511give 'configure' the option '--exec-prefix=PATH', 'make install' will
10512use PATH as the prefix for installing programs and libraries.
10513Documentation and other data files will still use the regular prefix.
10514
10515 If you would like to change the installation locations for a single
10516run, you can specify these variables as arguments to 'make': 'make
10517install exec_prefix=/' will install 'bash' and 'bashbug' into '/bin'
10518instead of the default '/usr/local/bin'.
10519
10520 If you want to see the files bash will install and where it will
10521install them without changing anything on your system, specify the
10522variable 'DESTDIR' as an argument to 'make'. Its value should be the
10523absolute directory path you'd like to use as the root of your sample
10524installation tree. For example,
10525
10526 mkdir /fs1/bash-install
10527 make install DESTDIR=/fs1/bash-install
10528
10529will install 'bash' into '/fs1/bash-install/usr/local/bin/bash', the
10530documentation into directories within
10531'/fs1/bash-install/usr/local/share', the example loadable builtins into
10532'/fs1/bash-install/usr/local/lib/bash', and so on. You can use the
10533usual 'exec_prefix' and 'prefix' variables to alter the directory paths
10534beneath the value of 'DESTDIR'.
10535
10536 The GNU Makefile standards provide a more complete description of
10537these variables and their effects.
10538
10539\1f
10540File: bashref.info, Node: Specifying the System Type, Next: Sharing Defaults, Prev: Installation Names, Up: Installing Bash
10541
1054210.5 Specifying the System Type
10543===============================
10544
10545There may be some features 'configure' can not figure out automatically,
10546but needs to determine by the type of host Bash will run on. Usually
10547'configure' can figure that out, but if it prints a message saying it
10548can not guess the host type, give it the '--host=TYPE' option. 'TYPE'
10549can either be a short name for the system type, such as 'sun4', or a
10550canonical name with three fields: 'CPU-COMPANY-SYSTEM' (e.g.,
10551'i386-unknown-freebsd4.2').
10552
10553 See the file 'support/config.sub' for the possible values of each
10554field.
10555
10556\1f
10557File: bashref.info, Node: Sharing Defaults, Next: Operation Controls, Prev: Specifying the System Type, Up: Installing Bash
10558
1055910.6 Sharing Defaults
10560=====================
10561
10562If you want to set default values for 'configure' scripts to share, you
10563can create a site shell script called 'config.site' that gives default
10564values for variables like 'CC', 'cache_file', and 'prefix'. 'configure'
10565looks for 'PREFIX/share/config.site' if it exists, then
10566'PREFIX/etc/config.site' if it exists. Or, you can set the
10567'CONFIG_SITE' environment variable to the location of the site script.
10568A warning: the Bash 'configure' looks for a site script, but not all
10569'configure' scripts do.
10570
10571\1f
10572File: bashref.info, Node: Operation Controls, Next: Optional Features, Prev: Sharing Defaults, Up: Installing Bash
10573
1057410.7 Operation Controls
10575=======================
10576
10577'configure' recognizes the following options to control how it operates.
10578
10579'--cache-file=FILE'
10580 Use and save the results of the tests in FILE instead of
10581 './config.cache'. Set FILE to '/dev/null' to disable caching, for
10582 debugging 'configure'.
10583
10584'--help'
10585 Print a summary of the options to 'configure', and exit.
10586
10587'--quiet'
10588'--silent'
10589'-q'
10590 Do not print messages saying which checks are being made.
10591
10592'--srcdir=DIR'
10593 Look for the Bash source code in directory DIR. Usually
10594 'configure' can determine that directory automatically.
10595
10596'--version'
10597 Print the version of Autoconf used to generate the 'configure'
10598 script, and exit.
10599
10600 'configure' also accepts some other, not widely used, boilerplate
10601options. 'configure --help' prints the complete list.
10602
10603\1f
10604File: bashref.info, Node: Optional Features, Prev: Operation Controls, Up: Installing Bash
10605
1060610.8 Optional Features
10607======================
10608
10609The Bash 'configure' has a number of '--enable-FEATURE' options, where
10610FEATURE indicates an optional part of Bash. There are also several
10611'--with-PACKAGE' options, where PACKAGE is something like 'bash-malloc'
10612or 'purify'. To turn off the default use of a package, use
10613'--without-PACKAGE'. To configure Bash without a feature that is
10614enabled by default, use '--disable-FEATURE'.
10615
10616 Here is a complete list of the '--enable-' and '--with-' options that
10617the Bash 'configure' recognizes.
10618
10619'--with-afs'
10620 Define if you are using the Andrew File System from Transarc.
10621
10622'--with-bash-malloc'
10623 Use the Bash version of 'malloc' in the directory 'lib/malloc'.
10624 This is not the same 'malloc' that appears in GNU libc, but an
10625 older version originally derived from the 4.2 BSD 'malloc'. This
10626 'malloc' is very fast, but wastes some space on each allocation.
10627 This option is enabled by default. The 'NOTES' file contains a
10628 list of systems for which this should be turned off, and
10629 'configure' disables this option automatically for a number of
10630 systems.
10631
10632'--with-curses'
10633 Use the curses library instead of the termcap library. This should
10634 be supplied if your system has an inadequate or incomplete termcap
10635 database.
10636
10637'--with-gnu-malloc'
10638 A synonym for '--with-bash-malloc'.
10639
10640'--with-installed-readline[=PREFIX]'
10641 Define this to make Bash link with a locally-installed version of
10642 Readline rather than the version in 'lib/readline'. This works
10643 only with Readline 5.0 and later versions. If PREFIX is 'yes' or
10644 not supplied, 'configure' uses the values of the make variables
10645 'includedir' and 'libdir', which are subdirectories of 'prefix' by
10646 default, to find the installed version of Readline if it is not in
10647 the standard system include and library directories. If PREFIX is
10648 'no', Bash links with the version in 'lib/readline'. If PREFIX is
10649 set to any other value, 'configure' treats it as a directory
10650 pathname and looks for the installed version of Readline in
10651 subdirectories of that directory (include files in PREFIX/'include'
10652 and the library in PREFIX/'lib').
10653
10654'--with-libintl-prefix[=PREFIX]'
10655 Define this to make Bash link with a locally-installed version of
10656 the libintl library instead of the version in 'lib/intl'.
10657
10658'--with-libiconv-prefix[=PREFIX]'
10659 Define this to make Bash look for libiconv in PREFIX instead of the
10660 standard system locations. There is no version included with Bash.
10661
10662'--enable-minimal-config'
10663 This produces a shell with minimal features, close to the
10664 historical Bourne shell.
10665
10666 There are several '--enable-' options that alter how Bash is
10667compiled, linked, and installed, rather than changing run-time features.
10668
10669'--enable-largefile'
10670 Enable support for large files
10671 (http://www.unix.org/version2/whatsnew/lfs20mar.html) if the
10672 operating system requires special compiler options to build
10673 programs which can access large files. This is enabled by default,
10674 if the operating system provides large file support.
10675
10676'--enable-profiling'
10677 This builds a Bash binary that produces profiling information to be
10678 processed by 'gprof' each time it is executed.
10679
10680'--enable-separate-helpfiles'
10681 Use external files for the documentation displayed by the 'help'
10682 builtin instead of storing the text internally.
10683
10684'--enable-static-link'
10685 This causes Bash to be linked statically, if 'gcc' is being used.
10686 This could be used to build a version to use as root's shell.
10687
10688 The 'minimal-config' option can be used to disable all of the
10689following options, but it is processed first, so individual options may
10690be enabled using 'enable-FEATURE'.
10691
10692 All of the following options except for 'alt-array-implementation',
10693'disabled-builtins', 'direxpand-default', 'strict-posix-default', and
10694'xpg-echo-default' are enabled by default, unless the operating system
10695does not provide the necessary support.
10696
10697'--enable-alias'
10698 Allow alias expansion and include the 'alias' and 'unalias'
10699 builtins (*note Aliases::).
10700
10701'--enable-alt-array-implementation'
10702 This builds bash using an alternate implementation of arrays (*note
10703 Arrays::) that provides faster access at the expense of using more
10704 memory (sometimes many times more, depending on how sparse an array
10705 is).
10706
10707'--enable-arith-for-command'
10708 Include support for the alternate form of the 'for' command that
10709 behaves like the C language 'for' statement (*note Looping
10710 Constructs::).
10711
10712'--enable-array-variables'
10713 Include support for one-dimensional array shell variables (*note
10714 Arrays::).
10715
10716'--enable-bang-history'
10717 Include support for 'csh'-like history substitution (*note History
10718 Interaction::).
10719
10720'--enable-brace-expansion'
10721 Include 'csh'-like brace expansion ( 'b{a,b}c' ==> 'bac bbc' ).
10722 See *note Brace Expansion::, for a complete description.
10723
10724'--enable-casemod-attributes'
10725 Include support for case-modifying attributes in the 'declare'
10726 builtin and assignment statements. Variables with the 'uppercase'
10727 attribute, for example, will have their values converted to
10728 uppercase upon assignment.
10729
10730'--enable-casemod-expansion'
10731 Include support for case-modifying word expansions.
10732
10733'--enable-command-timing'
10734 Include support for recognizing 'time' as a reserved word and for
10735 displaying timing statistics for the pipeline following 'time'
10736 (*note Pipelines::). This allows pipelines as well as shell
10737 builtins and functions to be timed.
10738
10739'--enable-cond-command'
10740 Include support for the '[[' conditional command. (*note
10741 Conditional Constructs::).
10742
10743'--enable-cond-regexp'
10744 Include support for matching POSIX regular expressions using the
10745 '=~' binary operator in the '[[' conditional command. (*note
10746 Conditional Constructs::).
10747
10748'--enable-coprocesses'
10749 Include support for coprocesses and the 'coproc' reserved word
10750 (*note Pipelines::).
10751
10752'--enable-debugger'
10753 Include support for the bash debugger (distributed separately).
10754
10755'--enable-dev-fd-stat-broken'
10756 If calling 'stat' on /dev/fd/N returns different results than
10757 calling 'fstat' on file descriptor N, supply this option to enable
10758 a workaround. This has implications for conditional commands that
10759 test file attributes.
10760
10761'--enable-direxpand-default'
10762 Cause the 'direxpand' shell option (*note The Shopt Builtin::) to
10763 be enabled by default when the shell starts. It is normally
10764 disabled by default.
10765
10766'--enable-directory-stack'
10767 Include support for a 'csh'-like directory stack and the 'pushd',
10768 'popd', and 'dirs' builtins (*note The Directory Stack::).
10769
10770'--enable-disabled-builtins'
10771 Allow builtin commands to be invoked via 'builtin xxx' even after
10772 'xxx' has been disabled using 'enable -n xxx'. See *note Bash
10773 Builtins::, for details of the 'builtin' and 'enable' builtin
10774 commands.
10775
10776'--enable-dparen-arithmetic'
10777 Include support for the '((...))' command (*note Conditional
10778 Constructs::).
10779
10780'--enable-extended-glob'
10781 Include support for the extended pattern matching features
10782 described above under *note Pattern Matching::.
10783
10784'--enable-extended-glob-default'
10785 Set the default value of the 'extglob' shell option described above
10786 under *note The Shopt Builtin:: to be enabled.
10787
10788'--enable-function-import'
10789 Include support for importing function definitions exported by
10790 another instance of the shell from the environment. This option is
10791 enabled by default.
10792
10793'--enable-glob-asciirange-default'
10794 Set the default value of the 'globasciiranges' shell option
10795 described above under *note The Shopt Builtin:: to be enabled.
10796 This controls the behavior of character ranges when used in pattern
10797 matching bracket expressions.
10798
10799'--enable-help-builtin'
10800 Include the 'help' builtin, which displays help on shell builtins
10801 and variables (*note Bash Builtins::).
10802
10803'--enable-history'
10804 Include command history and the 'fc' and 'history' builtin commands
10805 (*note Bash History Facilities::).
10806
10807'--enable-job-control'
10808 This enables the job control features (*note Job Control::), if the
10809 operating system supports them.
10810
10811'--enable-multibyte'
10812 This enables support for multibyte characters if the operating
10813 system provides the necessary support.
10814
10815'--enable-net-redirections'
10816 This enables the special handling of filenames of the form
10817 '/dev/tcp/HOST/PORT' and '/dev/udp/HOST/PORT' when used in
10818 redirections (*note Redirections::).
10819
10820'--enable-process-substitution'
10821 This enables process substitution (*note Process Substitution::) if
10822 the operating system provides the necessary support.
10823
10824'--enable-progcomp'
10825 Enable the programmable completion facilities (*note Programmable
10826 Completion::). If Readline is not enabled, this option has no
10827 effect.
10828
10829'--enable-prompt-string-decoding'
10830 Turn on the interpretation of a number of backslash-escaped
10831 characters in the '$PS0', '$PS1', '$PS2', and '$PS4' prompt
10832 strings. See *note Controlling the Prompt::, for a complete list
10833 of prompt string escape sequences.
10834
10835'--enable-readline'
10836 Include support for command-line editing and history with the Bash
10837 version of the Readline library (*note Command Line Editing::).
10838
10839'--enable-restricted'
10840 Include support for a "restricted shell". If this is enabled,
10841 Bash, when called as 'rbash', enters a restricted mode. See *note
10842 The Restricted Shell::, for a description of restricted mode.
10843
10844'--enable-select'
10845 Include the 'select' compound command, which allows the generation
10846 of simple menus (*note Conditional Constructs::).
10847
10848'--enable-single-help-strings'
10849 Store the text displayed by the 'help' builtin as a single string
10850 for each help topic. This aids in translating the text to
10851 different languages. You may need to disable this if your compiler
10852 cannot handle very long string literals.
10853
10854'--enable-strict-posix-default'
10855 Make Bash POSIX-conformant by default (*note Bash POSIX Mode::).
10856
10857'--enable-translatable-strings'
10858 Enable support for '$"STRING"' translatable strings (*note Locale
10859 Translation::).
10860
10861'--enable-usg-echo-default'
10862 A synonym for '--enable-xpg-echo-default'.
10863
10864'--enable-xpg-echo-default'
10865 Make the 'echo' builtin expand backslash-escaped characters by
10866 default, without requiring the '-e' option. This sets the default
10867 value of the 'xpg_echo' shell option to 'on', which makes the Bash
10868 'echo' behave more like the version specified in the Single Unix
10869 Specification, version 3. *Note Bash Builtins::, for a description
10870 of the escape sequences that 'echo' recognizes.
10871
10872 The file 'config-top.h' contains C Preprocessor '#define' statements
10873for options which are not settable from 'configure'. Some of these are
10874not meant to be changed; beware of the consequences if you do. Read the
10875comments associated with each definition for more information about its
10876effect.
10877
10878\1f
10879File: bashref.info, Node: Reporting Bugs, Next: Major Differences From The Bourne Shell, Prev: Installing Bash, Up: Top
10880
10881Appendix A Reporting Bugs
10882*************************
10883
10884Please report all bugs you find in Bash. But first, you should make
10885sure that it really is a bug, and that it appears in the latest version
10886of Bash. The latest version of Bash is always available for FTP from
10887<ftp://ftp.gnu.org/pub/gnu/bash/> and from
10888<http://git.savannah.gnu.org/cgit/bash.git/snapshot/bash-master.tar.gz>.
10889
10890 Once you have determined that a bug actually exists, use the
10891'bashbug' command to submit a bug report. If you have a fix, you are
10892encouraged to mail that as well! Suggestions and 'philosophical' bug
10893reports may be mailed to <bug-bash@gnu.org> or posted to the Usenet
10894newsgroup 'gnu.bash.bug'.
10895
10896 All bug reports should include:
10897 * The version number of Bash.
10898 * The hardware and operating system.
10899 * The compiler used to compile Bash.
10900 * A description of the bug behaviour.
10901 * A short script or 'recipe' which exercises the bug and may be used
10902 to reproduce it.
10903
10904'bashbug' inserts the first three items automatically into the template
10905it provides for filing a bug report.
10906
10907 Please send all reports concerning this manual to <bug-bash@gnu.org>.
10908
10909\1f
10910File: bashref.info, Node: Major Differences From The Bourne Shell, Next: GNU Free Documentation License, Prev: Reporting Bugs, Up: Top
10911
10912Appendix B Major Differences From The Bourne Shell
10913**************************************************
10914
10915Bash implements essentially the same grammar, parameter and variable
10916expansion, redirection, and quoting as the Bourne Shell. Bash uses the
10917POSIX standard as the specification of how these features are to be
10918implemented. There are some differences between the traditional Bourne
10919shell and Bash; this section quickly details the differences of
10920significance. A number of these differences are explained in greater
10921depth in previous sections. This section uses the version of 'sh'
10922included in SVR4.2 (the last version of the historical Bourne shell) as
10923the baseline reference.
10924
10925 * Bash is POSIX-conformant, even where the POSIX specification
10926 differs from traditional 'sh' behavior (*note Bash POSIX Mode::).
10927
10928 * Bash has multi-character invocation options (*note Invoking
10929 Bash::).
10930
10931 * Bash has command-line editing (*note Command Line Editing::) and
10932 the 'bind' builtin.
10933
10934 * Bash provides a programmable word completion mechanism (*note
10935 Programmable Completion::), and builtin commands 'complete',
10936 'compgen', and 'compopt', to manipulate it.
10937
10938 * Bash has command history (*note Bash History Facilities::) and the
10939 'history' and 'fc' builtins to manipulate it. The Bash history
10940 list maintains timestamp information and uses the value of the
10941 'HISTTIMEFORMAT' variable to display it.
10942
10943 * Bash implements 'csh'-like history expansion (*note History
10944 Interaction::).
10945
10946 * Bash has one-dimensional array variables (*note Arrays::), and the
10947 appropriate variable expansions and assignment syntax to use them.
10948 Several of the Bash builtins take options to act on arrays. Bash
10949 provides a number of built-in array variables.
10950
10951 * The '$'...'' quoting syntax, which expands ANSI-C backslash-escaped
10952 characters in the text between the single quotes, is supported
10953 (*note ANSI-C Quoting::).
10954
10955 * Bash supports the '$"..."' quoting syntax to do locale-specific
10956 translation of the characters between the double quotes. The '-D',
10957 '--dump-strings', and '--dump-po-strings' invocation options list
10958 the translatable strings found in a script (*note Locale
10959 Translation::).
10960
10961 * Bash implements the '!' keyword to negate the return value of a
10962 pipeline (*note Pipelines::). Very useful when an 'if' statement
10963 needs to act only if a test fails. The Bash '-o pipefail' option
10964 to 'set' will cause a pipeline to return a failure status if any
10965 command fails.
10966
10967 * Bash has the 'time' reserved word and command timing (*note
10968 Pipelines::). The display of the timing statistics may be
10969 controlled with the 'TIMEFORMAT' variable.
10970
10971 * Bash implements the 'for (( EXPR1 ; EXPR2 ; EXPR3 ))' arithmetic
10972 for command, similar to the C language (*note Looping
10973 Constructs::).
10974
10975 * Bash includes the 'select' compound command, which allows the
10976 generation of simple menus (*note Conditional Constructs::).
10977
10978 * Bash includes the '[[' compound command, which makes conditional
10979 testing part of the shell grammar (*note Conditional Constructs::),
10980 including optional regular expression matching.
10981
10982 * Bash provides optional case-insensitive matching for the 'case' and
10983 '[[' constructs.
10984
10985 * Bash includes brace expansion (*note Brace Expansion::) and tilde
10986 expansion (*note Tilde Expansion::).
10987
10988 * Bash implements command aliases and the 'alias' and 'unalias'
10989 builtins (*note Aliases::).
10990
10991 * Bash provides shell arithmetic, the '((' compound command (*note
10992 Conditional Constructs::), and arithmetic expansion (*note Shell
10993 Arithmetic::).
10994
10995 * Variables present in the shell's initial environment are
10996 automatically exported to child processes. The Bourne shell does
10997 not normally do this unless the variables are explicitly marked
10998 using the 'export' command.
10999
11000 * Bash supports the '+=' assignment operator, which appends to the
11001 value of the variable named on the left hand side.
11002
11003 * Bash includes the POSIX pattern removal '%', '#', '%%' and '##'
11004 expansions to remove leading or trailing substrings from variable
11005 values (*note Shell Parameter Expansion::).
11006
11007 * The expansion '${#xx}', which returns the length of '${xx}', is
11008 supported (*note Shell Parameter Expansion::).
11009
11010 * The expansion '${var:'OFFSET'[:'LENGTH']}', which expands to the
11011 substring of 'var''s value of length LENGTH, beginning at OFFSET,
11012 is present (*note Shell Parameter Expansion::).
11013
11014 * The expansion '${VAR/[/]'PATTERN'[/'REPLACEMENT']}', which matches
11015 PATTERN and replaces it with REPLACEMENT in the value of VAR, is
11016 available (*note Shell Parameter Expansion::).
11017
11018 * The expansion '${!PREFIX*}' expansion, which expands to the names
11019 of all shell variables whose names begin with PREFIX, is available
11020 (*note Shell Parameter Expansion::).
11021
11022 * Bash has indirect variable expansion using '${!word}' (*note Shell
11023 Parameter Expansion::).
11024
11025 * Bash can expand positional parameters beyond '$9' using '${NUM}'.
11026
11027 * The POSIX '$()' form of command substitution is implemented (*note
11028 Command Substitution::), and preferred to the Bourne shell's '``'
11029 (which is also implemented for backwards compatibility).
11030
11031 * Bash has process substitution (*note Process Substitution::).
11032
11033 * Bash automatically assigns variables that provide information about
11034 the current user ('UID', 'EUID', and 'GROUPS'), the current host
11035 ('HOSTTYPE', 'OSTYPE', 'MACHTYPE', and 'HOSTNAME'), and the
11036 instance of Bash that is running ('BASH', 'BASH_VERSION', and
11037 'BASH_VERSINFO'). *Note Bash Variables::, for details.
11038
11039 * The 'IFS' variable is used to split only the results of expansion,
11040 not all words (*note Word Splitting::). This closes a longstanding
11041 shell security hole.
11042
11043 * The filename expansion bracket expression code uses '!' and '^' to
11044 negate the set of characters between the brackets. The Bourne
11045 shell uses only '!'.
11046
11047 * Bash implements the full set of POSIX filename expansion operators,
11048 including character classes, equivalence classes, and collating
11049 symbols (*note Filename Expansion::).
11050
11051 * Bash implements extended pattern matching features when the
11052 'extglob' shell option is enabled (*note Pattern Matching::).
11053
11054 * It is possible to have a variable and a function with the same
11055 name; 'sh' does not separate the two name spaces.
11056
11057 * Bash functions are permitted to have local variables using the
11058 'local' builtin, and thus useful recursive functions may be written
11059 (*note Bash Builtins::).
11060
11061 * Variable assignments preceding commands affect only that command,
11062 even builtins and functions (*note Environment::). In 'sh', all
11063 variable assignments preceding commands are global unless the
11064 command is executed from the file system.
11065
11066 * Bash performs filename expansion on filenames specified as operands
11067 to input and output redirection operators (*note Redirections::).
11068
11069 * Bash contains the '<>' redirection operator, allowing a file to be
11070 opened for both reading and writing, and the '&>' redirection
11071 operator, for directing standard output and standard error to the
11072 same file (*note Redirections::).
11073
11074 * Bash includes the '<<<' redirection operator, allowing a string to
11075 be used as the standard input to a command.
11076
11077 * Bash implements the '[n]<&WORD' and '[n]>&WORD' redirection
11078 operators, which move one file descriptor to another.
11079
11080 * Bash treats a number of filenames specially when they are used in
11081 redirection operators (*note Redirections::).
11082
11083 * Bash can open network connections to arbitrary machines and
11084 services with the redirection operators (*note Redirections::).
11085
11086 * The 'noclobber' option is available to avoid overwriting existing
11087 files with output redirection (*note The Set Builtin::). The '>|'
11088 redirection operator may be used to override 'noclobber'.
11089
11090 * The Bash 'cd' and 'pwd' builtins (*note Bourne Shell Builtins::)
11091 each take '-L' and '-P' options to switch between logical and
11092 physical modes.
11093
11094 * Bash allows a function to override a builtin with the same name,
11095 and provides access to that builtin's functionality within the
11096 function via the 'builtin' and 'command' builtins (*note Bash
11097 Builtins::).
11098
11099 * The 'command' builtin allows selective disabling of functions when
11100 command lookup is performed (*note Bash Builtins::).
11101
11102 * Individual builtins may be enabled or disabled using the 'enable'
11103 builtin (*note Bash Builtins::).
11104
11105 * The Bash 'exec' builtin takes additional options that allow users
11106 to control the contents of the environment passed to the executed
11107 command, and what the zeroth argument to the command is to be
11108 (*note Bourne Shell Builtins::).
11109
11110 * Shell functions may be exported to children via the environment
11111 using 'export -f' (*note Shell Functions::).
11112
11113 * The Bash 'export', 'readonly', and 'declare' builtins can take a
11114 '-f' option to act on shell functions, a '-p' option to display
11115 variables with various attributes set in a format that can be used
11116 as shell input, a '-n' option to remove various variable
11117 attributes, and 'name=value' arguments to set variable attributes
11118 and values simultaneously.
11119
11120 * The Bash 'hash' builtin allows a name to be associated with an
11121 arbitrary filename, even when that filename cannot be found by
11122 searching the '$PATH', using 'hash -p' (*note Bourne Shell
11123 Builtins::).
11124
11125 * Bash includes a 'help' builtin for quick reference to shell
11126 facilities (*note Bash Builtins::).
11127
11128 * The 'printf' builtin is available to display formatted output
11129 (*note Bash Builtins::).
11130
11131 * The Bash 'read' builtin (*note Bash Builtins::) will read a line
11132 ending in '\' with the '-r' option, and will use the 'REPLY'
11133 variable as a default if no non-option arguments are supplied. The
11134 Bash 'read' builtin also accepts a prompt string with the '-p'
11135 option and will use Readline to obtain the line when given the '-e'
11136 option. The 'read' builtin also has additional options to control
11137 input: the '-s' option will turn off echoing of input characters as
11138 they are read, the '-t' option will allow 'read' to time out if
11139 input does not arrive within a specified number of seconds, the
11140 '-n' option will allow reading only a specified number of
11141 characters rather than a full line, and the '-d' option will read
11142 until a particular character rather than newline.
11143
11144 * The 'return' builtin may be used to abort execution of scripts
11145 executed with the '.' or 'source' builtins (*note Bourne Shell
11146 Builtins::).
11147
11148 * Bash includes the 'shopt' builtin, for finer control of shell
11149 optional capabilities (*note The Shopt Builtin::), and allows these
11150 options to be set and unset at shell invocation (*note Invoking
11151 Bash::).
11152
11153 * Bash has much more optional behavior controllable with the 'set'
11154 builtin (*note The Set Builtin::).
11155
11156 * The '-x' ('xtrace') option displays commands other than simple
11157 commands when performing an execution trace (*note The Set
11158 Builtin::).
11159
11160 * The 'test' builtin (*note Bourne Shell Builtins::) is slightly
11161 different, as it implements the POSIX algorithm, which specifies
11162 the behavior based on the number of arguments.
11163
11164 * Bash includes the 'caller' builtin, which displays the context of
11165 any active subroutine call (a shell function or a script executed
11166 with the '.' or 'source' builtins). This supports the Bash
11167 debugger.
11168
11169 * The 'trap' builtin (*note Bourne Shell Builtins::) allows a 'DEBUG'
11170 pseudo-signal specification, similar to 'EXIT'. Commands specified
11171 with a 'DEBUG' trap are executed before every simple command, 'for'
11172 command, 'case' command, 'select' command, every arithmetic 'for'
11173 command, and before the first command executes in a shell function.
11174 The 'DEBUG' trap is not inherited by shell functions unless the
11175 function has been given the 'trace' attribute or the 'functrace'
11176 option has been enabled using the 'shopt' builtin. The 'extdebug'
11177 shell option has additional effects on the 'DEBUG' trap.
11178
11179 The 'trap' builtin (*note Bourne Shell Builtins::) allows an 'ERR'
11180 pseudo-signal specification, similar to 'EXIT' and 'DEBUG'.
11181 Commands specified with an 'ERR' trap are executed after a simple
11182 command fails, with a few exceptions. The 'ERR' trap is not
11183 inherited by shell functions unless the '-o errtrace' option to the
11184 'set' builtin is enabled.
11185
11186 The 'trap' builtin (*note Bourne Shell Builtins::) allows a
11187 'RETURN' pseudo-signal specification, similar to 'EXIT' and
11188 'DEBUG'. Commands specified with a 'RETURN' trap are executed
11189 before execution resumes after a shell function or a shell script
11190 executed with '.' or 'source' returns. The 'RETURN' trap is not
11191 inherited by shell functions unless the function has been given the
11192 'trace' attribute or the 'functrace' option has been enabled using
11193 the 'shopt' builtin.
11194
11195 * The Bash 'type' builtin is more extensive and gives more
11196 information about the names it finds (*note Bash Builtins::).
11197
11198 * The Bash 'umask' builtin permits a '-p' option to cause the output
11199 to be displayed in the form of a 'umask' command that may be reused
11200 as input (*note Bourne Shell Builtins::).
11201
11202 * Bash implements a 'csh'-like directory stack, and provides the
11203 'pushd', 'popd', and 'dirs' builtins to manipulate it (*note The
11204 Directory Stack::). Bash also makes the directory stack visible as
11205 the value of the 'DIRSTACK' shell variable.
11206
11207 * Bash interprets special backslash-escaped characters in the prompt
11208 strings when interactive (*note Controlling the Prompt::).
11209
11210 * The Bash restricted mode is more useful (*note The Restricted
11211 Shell::); the SVR4.2 shell restricted mode is too limited.
11212
11213 * The 'disown' builtin can remove a job from the internal shell job
11214 table (*note Job Control Builtins::) or suppress the sending of
11215 'SIGHUP' to a job when the shell exits as the result of a 'SIGHUP'.
11216
11217 * Bash includes a number of features to support a separate debugger
11218 for shell scripts.
11219
11220 * The SVR4.2 shell has two privilege-related builtins ('mldmode' and
11221 'priv') not present in Bash.
11222
11223 * Bash does not have the 'stop' or 'newgrp' builtins.
11224
11225 * Bash does not use the 'SHACCT' variable or perform shell
11226 accounting.
11227
11228 * The SVR4.2 'sh' uses a 'TIMEOUT' variable like Bash uses 'TMOUT'.
11229
11230More features unique to Bash may be found in *note Bash Features::.
11231
11232B.1 Implementation Differences From The SVR4.2 Shell
11233====================================================
11234
11235Since Bash is a completely new implementation, it does not suffer from
11236many of the limitations of the SVR4.2 shell. For instance:
11237
11238 * Bash does not fork a subshell when redirecting into or out of a
11239 shell control structure such as an 'if' or 'while' statement.
11240
11241 * Bash does not allow unbalanced quotes. The SVR4.2 shell will
11242 silently insert a needed closing quote at 'EOF' under certain
11243 circumstances. This can be the cause of some hard-to-find errors.
11244
11245 * The SVR4.2 shell uses a baroque memory management scheme based on
11246 trapping 'SIGSEGV'. If the shell is started from a process with
11247 'SIGSEGV' blocked (e.g., by using the 'system()' C library function
11248 call), it misbehaves badly.
11249
11250 * In a questionable attempt at security, the SVR4.2 shell, when
11251 invoked without the '-p' option, will alter its real and effective
11252 UID and GID if they are less than some magic threshold value,
11253 commonly 100. This can lead to unexpected results.
11254
11255 * The SVR4.2 shell does not allow users to trap 'SIGSEGV', 'SIGALRM',
11256 or 'SIGCHLD'.
11257
11258 * The SVR4.2 shell does not allow the 'IFS', 'MAILCHECK', 'PATH',
11259 'PS1', or 'PS2' variables to be unset.
11260
11261 * The SVR4.2 shell treats '^' as the undocumented equivalent of '|'.
11262
11263 * Bash allows multiple option arguments when it is invoked ('-x -v');
11264 the SVR4.2 shell allows only one option argument ('-xv'). In fact,
11265 some versions of the shell dump core if the second argument begins
11266 with a '-'.
11267
11268 * The SVR4.2 shell exits a script if any builtin fails; Bash exits a
11269 script only if one of the POSIX special builtins fails, and only
11270 for certain failures, as enumerated in the POSIX standard.
11271
11272 * The SVR4.2 shell behaves differently when invoked as 'jsh' (it
11273 turns on job control).
11274
11275\1f
11276File: bashref.info, Node: GNU Free Documentation License, Next: Indexes, Prev: Major Differences From The Bourne Shell, Up: Top
11277
11278Appendix C GNU Free Documentation License
11279*****************************************
11280
11281 Version 1.3, 3 November 2008
11282
11283 Copyright (C) 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.
11284 <http://fsf.org/>
11285
11286 Everyone is permitted to copy and distribute verbatim copies
11287 of this license document, but changing it is not allowed.
11288
11289 0. PREAMBLE
11290
11291 The purpose of this License is to make a manual, textbook, or other
11292 functional and useful document "free" in the sense of freedom: to
11293 assure everyone the effective freedom to copy and redistribute it,
11294 with or without modifying it, either commercially or
11295 noncommercially. Secondarily, this License preserves for the
11296 author and publisher a way to get credit for their work, while not
11297 being considered responsible for modifications made by others.
11298
11299 This License is a kind of "copyleft", which means that derivative
11300 works of the document must themselves be free in the same sense.
11301 It complements the GNU General Public License, which is a copyleft
11302 license designed for free software.
11303
11304 We have designed this License in order to use it for manuals for
11305 free software, because free software needs free documentation: a
11306 free program should come with manuals providing the same freedoms
11307 that the software does. But this License is not limited to
11308 software manuals; it can be used for any textual work, regardless
11309 of subject matter or whether it is published as a printed book. We
11310 recommend this License principally for works whose purpose is
11311 instruction or reference.
11312
11313 1. APPLICABILITY AND DEFINITIONS
11314
11315 This License applies to any manual or other work, in any medium,
11316 that contains a notice placed by the copyright holder saying it can
11317 be distributed under the terms of this License. Such a notice
11318 grants a world-wide, royalty-free license, unlimited in duration,
11319 to use that work under the conditions stated herein. The
11320 "Document", below, refers to any such manual or work. Any member
11321 of the public is a licensee, and is addressed as "you". You accept
11322 the license if you copy, modify or distribute the work in a way
11323 requiring permission under copyright law.
11324
11325 A "Modified Version" of the Document means any work containing the
11326 Document or a portion of it, either copied verbatim, or with
11327 modifications and/or translated into another language.
11328
11329 A "Secondary Section" is a named appendix or a front-matter section
11330 of the Document that deals exclusively with the relationship of the
11331 publishers or authors of the Document to the Document's overall
11332 subject (or to related matters) and contains nothing that could
11333 fall directly within that overall subject. (Thus, if the Document
11334 is in part a textbook of mathematics, a Secondary Section may not
11335 explain any mathematics.) The relationship could be a matter of
11336 historical connection with the subject or with related matters, or
11337 of legal, commercial, philosophical, ethical or political position
11338 regarding them.
11339
11340 The "Invariant Sections" are certain Secondary Sections whose
11341 titles are designated, as being those of Invariant Sections, in the
11342 notice that says that the Document is released under this License.
11343 If a section does not fit the above definition of Secondary then it
11344 is not allowed to be designated as Invariant. The Document may
11345 contain zero Invariant Sections. If the Document does not identify
11346 any Invariant Sections then there are none.
11347
11348 The "Cover Texts" are certain short passages of text that are
11349 listed, as Front-Cover Texts or Back-Cover Texts, in the notice
11350 that says that the Document is released under this License. A
11351 Front-Cover Text may be at most 5 words, and a Back-Cover Text may
11352 be at most 25 words.
11353
11354 A "Transparent" copy of the Document means a machine-readable copy,
11355 represented in a format whose specification is available to the
11356 general public, that is suitable for revising the document
11357 straightforwardly with generic text editors or (for images composed
11358 of pixels) generic paint programs or (for drawings) some widely
11359 available drawing editor, and that is suitable for input to text
11360 formatters or for automatic translation to a variety of formats
11361 suitable for input to text formatters. A copy made in an otherwise
11362 Transparent file format whose markup, or absence of markup, has
11363 been arranged to thwart or discourage subsequent modification by
11364 readers is not Transparent. An image format is not Transparent if
11365 used for any substantial amount of text. A copy that is not
11366 "Transparent" is called "Opaque".
11367
11368 Examples of suitable formats for Transparent copies include plain
11369 ASCII without markup, Texinfo input format, LaTeX input format,
11370 SGML or XML using a publicly available DTD, and standard-conforming
11371 simple HTML, PostScript or PDF designed for human modification.
11372 Examples of transparent image formats include PNG, XCF and JPG.
11373 Opaque formats include proprietary formats that can be read and
11374 edited only by proprietary word processors, SGML or XML for which
11375 the DTD and/or processing tools are not generally available, and
11376 the machine-generated HTML, PostScript or PDF produced by some word
11377 processors for output purposes only.
11378
11379 The "Title Page" means, for a printed book, the title page itself,
11380 plus such following pages as are needed to hold, legibly, the
11381 material this License requires to appear in the title page. For
11382 works in formats which do not have any title page as such, "Title
11383 Page" means the text near the most prominent appearance of the
11384 work's title, preceding the beginning of the body of the text.
11385
11386 The "publisher" means any person or entity that distributes copies
11387 of the Document to the public.
11388
11389 A section "Entitled XYZ" means a named subunit of the Document
11390 whose title either is precisely XYZ or contains XYZ in parentheses
11391 following text that translates XYZ in another language. (Here XYZ
11392 stands for a specific section name mentioned below, such as
11393 "Acknowledgements", "Dedications", "Endorsements", or "History".)
11394 To "Preserve the Title" of such a section when you modify the
11395 Document means that it remains a section "Entitled XYZ" according
11396 to this definition.
11397
11398 The Document may include Warranty Disclaimers next to the notice
11399 which states that this License applies to the Document. These
11400 Warranty Disclaimers are considered to be included by reference in
11401 this License, but only as regards disclaiming warranties: any other
11402 implication that these Warranty Disclaimers may have is void and
11403 has no effect on the meaning of this License.
11404
11405 2. VERBATIM COPYING
11406
11407 You may copy and distribute the Document in any medium, either
11408 commercially or noncommercially, provided that this License, the
11409 copyright notices, and the license notice saying this License
11410 applies to the Document are reproduced in all copies, and that you
11411 add no other conditions whatsoever to those of this License. You
11412 may not use technical measures to obstruct or control the reading
11413 or further copying of the copies you make or distribute. However,
11414 you may accept compensation in exchange for copies. If you
11415 distribute a large enough number of copies you must also follow the
11416 conditions in section 3.
11417
11418 You may also lend copies, under the same conditions stated above,
11419 and you may publicly display copies.
11420
11421 3. COPYING IN QUANTITY
11422
11423 If you publish printed copies (or copies in media that commonly
11424 have printed covers) of the Document, numbering more than 100, and
11425 the Document's license notice requires Cover Texts, you must
11426 enclose the copies in covers that carry, clearly and legibly, all
11427 these Cover Texts: Front-Cover Texts on the front cover, and
11428 Back-Cover Texts on the back cover. Both covers must also clearly
11429 and legibly identify you as the publisher of these copies. The
11430 front cover must present the full title with all words of the title
11431 equally prominent and visible. You may add other material on the
11432 covers in addition. Copying with changes limited to the covers, as
11433 long as they preserve the title of the Document and satisfy these
11434 conditions, can be treated as verbatim copying in other respects.
11435
11436 If the required texts for either cover are too voluminous to fit
11437 legibly, you should put the first ones listed (as many as fit
11438 reasonably) on the actual cover, and continue the rest onto
11439 adjacent pages.
11440
11441 If you publish or distribute Opaque copies of the Document
11442 numbering more than 100, you must either include a machine-readable
11443 Transparent copy along with each Opaque copy, or state in or with
11444 each Opaque copy a computer-network location from which the general
11445 network-using public has access to download using public-standard
11446 network protocols a complete Transparent copy of the Document, free
11447 of added material. If you use the latter option, you must take
11448 reasonably prudent steps, when you begin distribution of Opaque
11449 copies in quantity, to ensure that this Transparent copy will
11450 remain thus accessible at the stated location until at least one
11451 year after the last time you distribute an Opaque copy (directly or
11452 through your agents or retailers) of that edition to the public.
11453
11454 It is requested, but not required, that you contact the authors of
11455 the Document well before redistributing any large number of copies,
11456 to give them a chance to provide you with an updated version of the
11457 Document.
11458
11459 4. MODIFICATIONS
11460
11461 You may copy and distribute a Modified Version of the Document
11462 under the conditions of sections 2 and 3 above, provided that you
11463 release the Modified Version under precisely this License, with the
11464 Modified Version filling the role of the Document, thus licensing
11465 distribution and modification of the Modified Version to whoever
11466 possesses a copy of it. In addition, you must do these things in
11467 the Modified Version:
11468
11469 A. Use in the Title Page (and on the covers, if any) a title
11470 distinct from that of the Document, and from those of previous
11471 versions (which should, if there were any, be listed in the
11472 History section of the Document). You may use the same title
11473 as a previous version if the original publisher of that
11474 version gives permission.
11475
11476 B. List on the Title Page, as authors, one or more persons or
11477 entities responsible for authorship of the modifications in
11478 the Modified Version, together with at least five of the
11479 principal authors of the Document (all of its principal
11480 authors, if it has fewer than five), unless they release you
11481 from this requirement.
11482
11483 C. State on the Title page the name of the publisher of the
11484 Modified Version, as the publisher.
11485
11486 D. Preserve all the copyright notices of the Document.
11487
11488 E. Add an appropriate copyright notice for your modifications
11489 adjacent to the other copyright notices.
11490
11491 F. Include, immediately after the copyright notices, a license
11492 notice giving the public permission to use the Modified
11493 Version under the terms of this License, in the form shown in
11494 the Addendum below.
11495
11496 G. Preserve in that license notice the full lists of Invariant
11497 Sections and required Cover Texts given in the Document's
11498 license notice.
11499
11500 H. Include an unaltered copy of this License.
11501
11502 I. Preserve the section Entitled "History", Preserve its Title,
11503 and add to it an item stating at least the title, year, new
11504 authors, and publisher of the Modified Version as given on the
11505 Title Page. If there is no section Entitled "History" in the
11506 Document, create one stating the title, year, authors, and
11507 publisher of the Document as given on its Title Page, then add
11508 an item describing the Modified Version as stated in the
11509 previous sentence.
11510
11511 J. Preserve the network location, if any, given in the Document
11512 for public access to a Transparent copy of the Document, and
11513 likewise the network locations given in the Document for
11514 previous versions it was based on. These may be placed in the
11515 "History" section. You may omit a network location for a work
11516 that was published at least four years before the Document
11517 itself, or if the original publisher of the version it refers
11518 to gives permission.
11519
11520 K. For any section Entitled "Acknowledgements" or "Dedications",
11521 Preserve the Title of the section, and preserve in the section
11522 all the substance and tone of each of the contributor
11523 acknowledgements and/or dedications given therein.
11524
11525 L. Preserve all the Invariant Sections of the Document, unaltered
11526 in their text and in their titles. Section numbers or the
11527 equivalent are not considered part of the section titles.
11528
11529 M. Delete any section Entitled "Endorsements". Such a section
11530 may not be included in the Modified Version.
11531
11532 N. Do not retitle any existing section to be Entitled
11533 "Endorsements" or to conflict in title with any Invariant
11534 Section.
11535
11536 O. Preserve any Warranty Disclaimers.
11537
11538 If the Modified Version includes new front-matter sections or
11539 appendices that qualify as Secondary Sections and contain no
11540 material copied from the Document, you may at your option designate
11541 some or all of these sections as invariant. To do this, add their
11542 titles to the list of Invariant Sections in the Modified Version's
11543 license notice. These titles must be distinct from any other
11544 section titles.
11545
11546 You may add a section Entitled "Endorsements", provided it contains
11547 nothing but endorsements of your Modified Version by various
11548 parties--for example, statements of peer review or that the text
11549 has been approved by an organization as the authoritative
11550 definition of a standard.
11551
11552 You may add a passage of up to five words as a Front-Cover Text,
11553 and a passage of up to 25 words as a Back-Cover Text, to the end of
11554 the list of Cover Texts in the Modified Version. Only one passage
11555 of Front-Cover Text and one of Back-Cover Text may be added by (or
11556 through arrangements made by) any one entity. If the Document
11557 already includes a cover text for the same cover, previously added
11558 by you or by arrangement made by the same entity you are acting on
11559 behalf of, you may not add another; but you may replace the old
11560 one, on explicit permission from the previous publisher that added
11561 the old one.
11562
11563 The author(s) and publisher(s) of the Document do not by this
11564 License give permission to use their names for publicity for or to
11565 assert or imply endorsement of any Modified Version.
11566
11567 5. COMBINING DOCUMENTS
11568
11569 You may combine the Document with other documents released under
11570 this License, under the terms defined in section 4 above for
11571 modified versions, provided that you include in the combination all
11572 of the Invariant Sections of all of the original documents,
11573 unmodified, and list them all as Invariant Sections of your
11574 combined work in its license notice, and that you preserve all
11575 their Warranty Disclaimers.
11576
11577 The combined work need only contain one copy of this License, and
11578 multiple identical Invariant Sections may be replaced with a single
11579 copy. If there are multiple Invariant Sections with the same name
11580 but different contents, make the title of each such section unique
11581 by adding at the end of it, in parentheses, the name of the
11582 original author or publisher of that section if known, or else a
11583 unique number. Make the same adjustment to the section titles in
11584 the list of Invariant Sections in the license notice of the
11585 combined work.
11586
11587 In the combination, you must combine any sections Entitled
11588 "History" in the various original documents, forming one section
11589 Entitled "History"; likewise combine any sections Entitled
11590 "Acknowledgements", and any sections Entitled "Dedications". You
11591 must delete all sections Entitled "Endorsements."
11592
11593 6. COLLECTIONS OF DOCUMENTS
11594
11595 You may make a collection consisting of the Document and other
11596 documents released under this License, and replace the individual
11597 copies of this License in the various documents with a single copy
11598 that is included in the collection, provided that you follow the
11599 rules of this License for verbatim copying of each of the documents
11600 in all other respects.
11601
11602 You may extract a single document from such a collection, and
11603 distribute it individually under this License, provided you insert
11604 a copy of this License into the extracted document, and follow this
11605 License in all other respects regarding verbatim copying of that
11606 document.
11607
11608 7. AGGREGATION WITH INDEPENDENT WORKS
11609
11610 A compilation of the Document or its derivatives with other
11611 separate and independent documents or works, in or on a volume of a
11612 storage or distribution medium, is called an "aggregate" if the
11613 copyright resulting from the compilation is not used to limit the
11614 legal rights of the compilation's users beyond what the individual
11615 works permit. When the Document is included in an aggregate, this
11616 License does not apply to the other works in the aggregate which
11617 are not themselves derivative works of the Document.
11618
11619 If the Cover Text requirement of section 3 is applicable to these
11620 copies of the Document, then if the Document is less than one half
11621 of the entire aggregate, the Document's Cover Texts may be placed
11622 on covers that bracket the Document within the aggregate, or the
11623 electronic equivalent of covers if the Document is in electronic
11624 form. Otherwise they must appear on printed covers that bracket
11625 the whole aggregate.
11626
11627 8. TRANSLATION
11628
11629 Translation is considered a kind of modification, so you may
11630 distribute translations of the Document under the terms of section
11631 4. Replacing Invariant Sections with translations requires special
11632 permission from their copyright holders, but you may include
11633 translations of some or all Invariant Sections in addition to the
11634 original versions of these Invariant Sections. You may include a
11635 translation of this License, and all the license notices in the
11636 Document, and any Warranty Disclaimers, provided that you also
11637 include the original English version of this License and the
11638 original versions of those notices and disclaimers. In case of a
11639 disagreement between the translation and the original version of
11640 this License or a notice or disclaimer, the original version will
11641 prevail.
11642
11643 If a section in the Document is Entitled "Acknowledgements",
11644 "Dedications", or "History", the requirement (section 4) to
11645 Preserve its Title (section 1) will typically require changing the
11646 actual title.
11647
11648 9. TERMINATION
11649
11650 You may not copy, modify, sublicense, or distribute the Document
11651 except as expressly provided under this License. Any attempt
11652 otherwise to copy, modify, sublicense, or distribute it is void,
11653 and will automatically terminate your rights under this License.
11654
11655 However, if you cease all violation of this License, then your
11656 license from a particular copyright holder is reinstated (a)
11657 provisionally, unless and until the copyright holder explicitly and
11658 finally terminates your license, and (b) permanently, if the
11659 copyright holder fails to notify you of the violation by some
11660 reasonable means prior to 60 days after the cessation.
11661
11662 Moreover, your license from a particular copyright holder is
11663 reinstated permanently if the copyright holder notifies you of the
11664 violation by some reasonable means, this is the first time you have
11665 received notice of violation of this License (for any work) from
11666 that copyright holder, and you cure the violation prior to 30 days
11667 after your receipt of the notice.
11668
11669 Termination of your rights under this section does not terminate
11670 the licenses of parties who have received copies or rights from you
11671 under this License. If your rights have been terminated and not
11672 permanently reinstated, receipt of a copy of some or all of the
11673 same material does not give you any rights to use it.
11674
11675 10. FUTURE REVISIONS OF THIS LICENSE
11676
11677 The Free Software Foundation may publish new, revised versions of
11678 the GNU Free Documentation License from time to time. Such new
11679 versions will be similar in spirit to the present version, but may
11680 differ in detail to address new problems or concerns. See
11681 <http://www.gnu.org/copyleft/>.
11682
11683 Each version of the License is given a distinguishing version
11684 number. If the Document specifies that a particular numbered
11685 version of this License "or any later version" applies to it, you
11686 have the option of following the terms and conditions either of
11687 that specified version or of any later version that has been
11688 published (not as a draft) by the Free Software Foundation. If the
11689 Document does not specify a version number of this License, you may
11690 choose any version ever published (not as a draft) by the Free
11691 Software Foundation. If the Document specifies that a proxy can
11692 decide which future versions of this License can be used, that
11693 proxy's public statement of acceptance of a version permanently
11694 authorizes you to choose that version for the Document.
11695
11696 11. RELICENSING
11697
11698 "Massive Multiauthor Collaboration Site" (or "MMC Site") means any
11699 World Wide Web server that publishes copyrightable works and also
11700 provides prominent facilities for anybody to edit those works. A
11701 public wiki that anybody can edit is an example of such a server.
11702 A "Massive Multiauthor Collaboration" (or "MMC") contained in the
11703 site means any set of copyrightable works thus published on the MMC
11704 site.
11705
11706 "CC-BY-SA" means the Creative Commons Attribution-Share Alike 3.0
11707 license published by Creative Commons Corporation, a not-for-profit
11708 corporation with a principal place of business in San Francisco,
11709 California, as well as future copyleft versions of that license
11710 published by that same organization.
11711
11712 "Incorporate" means to publish or republish a Document, in whole or
11713 in part, as part of another Document.
11714
11715 An MMC is "eligible for relicensing" if it is licensed under this
11716 License, and if all works that were first published under this
11717 License somewhere other than this MMC, and subsequently
11718 incorporated in whole or in part into the MMC, (1) had no cover
11719 texts or invariant sections, and (2) were thus incorporated prior
11720 to November 1, 2008.
11721
11722 The operator of an MMC Site may republish an MMC contained in the
11723 site under CC-BY-SA on the same site at any time before August 1,
11724 2009, provided the MMC is eligible for relicensing.
11725
11726ADDENDUM: How to use this License for your documents
11727====================================================
11728
11729To use this License in a document you have written, include a copy of
11730the License in the document and put the following copyright and license
11731notices just after the title page:
11732
11733 Copyright (C) YEAR YOUR NAME.
11734 Permission is granted to copy, distribute and/or modify this document
11735 under the terms of the GNU Free Documentation License, Version 1.3
11736 or any later version published by the Free Software Foundation;
11737 with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
11738 Texts. A copy of the license is included in the section entitled ``GNU
11739 Free Documentation License''.
11740
11741 If you have Invariant Sections, Front-Cover Texts and Back-Cover
11742Texts, replace the "with...Texts." line with this:
11743
11744 with the Invariant Sections being LIST THEIR TITLES, with
11745 the Front-Cover Texts being LIST, and with the Back-Cover Texts
11746 being LIST.
11747
11748 If you have Invariant Sections without Cover Texts, or some other
11749combination of the three, merge those two alternatives to suit the
11750situation.
11751
11752 If your document contains nontrivial examples of program code, we
11753recommend releasing these examples in parallel under your choice of free
11754software license, such as the GNU General Public License, to permit
11755their use in free software.
11756
11757\1f
11758File: bashref.info, Node: Indexes, Prev: GNU Free Documentation License, Up: Top
11759
11760Appendix D Indexes
11761******************
11762
11763* Menu:
11764
11765* Builtin Index:: Index of Bash builtin commands.
11766* Reserved Word Index:: Index of Bash reserved words.
11767* Variable Index:: Quick reference helps you find the
11768 variable you want.
11769* Function Index:: Index of bindable Readline functions.
11770* Concept Index:: General index for concepts described in
11771 this manual.
11772
11773\1f
11774File: bashref.info, Node: Builtin Index, Next: Reserved Word Index, Up: Indexes
11775
11776D.1 Index of Shell Builtin Commands
11777===================================
11778
11779\0\b[index\0\b]
11780* Menu:
11781
11782* .: Bourne Shell Builtins.
11783 (line 17)
11784* :: Bourne Shell Builtins.
11785 (line 11)
11786* [: Bourne Shell Builtins.
11787 (line 275)
11788* alias: Bash Builtins. (line 11)
11789* bg: Job Control Builtins.
11790 (line 7)
11791* bind: Bash Builtins. (line 21)
11792* break: Bourne Shell Builtins.
11793 (line 37)
11794* builtin: Bash Builtins. (line 108)
11795* caller: Bash Builtins. (line 117)
11796* cd: Bourne Shell Builtins.
11797 (line 45)
11798* command: Bash Builtins. (line 134)
11799* compgen: Programmable Completion Builtins.
11800 (line 12)
11801* complete: Programmable Completion Builtins.
11802 (line 30)
11803* compopt: Programmable Completion Builtins.
11804 (line 238)
11805* continue: Bourne Shell Builtins.
11806 (line 90)
11807* declare: Bash Builtins. (line 154)
11808* dirs: Directory Stack Builtins.
11809 (line 7)
11810* disown: Job Control Builtins.
11811 (line 104)
11812* echo: Bash Builtins. (line 257)
11813* enable: Bash Builtins. (line 306)
11814* eval: Bourne Shell Builtins.
11815 (line 99)
11816* exec: Bourne Shell Builtins.
11817 (line 107)
11818* exit: Bourne Shell Builtins.
11819 (line 125)
11820* export: Bourne Shell Builtins.
11821 (line 132)
11822* fc: Bash History Builtins.
11823 (line 10)
11824* fg: Job Control Builtins.
11825 (line 17)
11826* getopts: Bourne Shell Builtins.
11827 (line 148)
11828* hash: Bourne Shell Builtins.
11829 (line 192)
11830* help: Bash Builtins. (line 342)
11831* history: Bash History Builtins.
11832 (line 46)
11833* jobs: Job Control Builtins.
11834 (line 27)
11835* kill: Job Control Builtins.
11836 (line 58)
11837* let: Bash Builtins. (line 361)
11838* local: Bash Builtins. (line 369)
11839* logout: Bash Builtins. (line 385)
11840* mapfile: Bash Builtins. (line 390)
11841* popd: Directory Stack Builtins.
11842 (line 35)
11843* printf: Bash Builtins. (line 436)
11844* pushd: Directory Stack Builtins.
11845 (line 69)
11846* pwd: Bourne Shell Builtins.
11847 (line 212)
11848* read: Bash Builtins. (line 488)
11849* readarray: Bash Builtins. (line 585)
11850* readonly: Bourne Shell Builtins.
11851 (line 222)
11852* return: Bourne Shell Builtins.
11853 (line 241)
11854* set: The Set Builtin. (line 11)
11855* shift: Bourne Shell Builtins.
11856 (line 262)
11857* shopt: The Shopt Builtin. (line 9)
11858* source: Bash Builtins. (line 594)
11859* suspend: Job Control Builtins.
11860 (line 116)
11861* test: Bourne Shell Builtins.
11862 (line 275)
11863* times: Bourne Shell Builtins.
11864 (line 360)
11865* trap: Bourne Shell Builtins.
11866 (line 366)
11867* type: Bash Builtins. (line 599)
11868* typeset: Bash Builtins. (line 631)
11869* ulimit: Bash Builtins. (line 637)
11870* umask: Bourne Shell Builtins.
11871 (line 415)
11872* unalias: Bash Builtins. (line 743)
11873* unset: Bourne Shell Builtins.
11874 (line 433)
11875* wait: Job Control Builtins.
11876 (line 76)
11877
11878\1f
11879File: bashref.info, Node: Reserved Word Index, Next: Variable Index, Prev: Builtin Index, Up: Indexes
11880
11881D.2 Index of Shell Reserved Words
11882=================================
11883
11884\0\b[index\0\b]
11885* Menu:
11886
11887* !: Pipelines. (line 9)
11888* [[: Conditional Constructs.
11889 (line 126)
11890* ]]: Conditional Constructs.
11891 (line 126)
11892* {: Command Grouping. (line 21)
11893* }: Command Grouping. (line 21)
11894* case: Conditional Constructs.
11895 (line 28)
11896* do: Looping Constructs. (line 12)
11897* done: Looping Constructs. (line 12)
11898* elif: Conditional Constructs.
11899 (line 7)
11900* else: Conditional Constructs.
11901 (line 7)
11902* esac: Conditional Constructs.
11903 (line 28)
11904* fi: Conditional Constructs.
11905 (line 7)
11906* for: Looping Constructs. (line 32)
11907* function: Shell Functions. (line 13)
11908* if: Conditional Constructs.
11909 (line 7)
11910* in: Conditional Constructs.
11911 (line 28)
11912* select: Conditional Constructs.
11913 (line 84)
11914* then: Conditional Constructs.
11915 (line 7)
11916* time: Pipelines. (line 9)
11917* until: Looping Constructs. (line 12)
11918* while: Looping Constructs. (line 22)
11919
11920\1f
11921File: bashref.info, Node: Variable Index, Next: Function Index, Prev: Reserved Word Index, Up: Indexes
11922
11923D.3 Parameter and Variable Index
11924================================
11925
11926\0\b[index\0\b]
11927* Menu:
11928
11929* !: Special Parameters. (line 55)
11930* #: Special Parameters. (line 39)
11931* $: Special Parameters. (line 51)
11932* $!: Special Parameters. (line 56)
11933* $#: Special Parameters. (line 40)
11934* $$: Special Parameters. (line 52)
11935* $*: Special Parameters. (line 10)
11936* $-: Special Parameters. (line 47)
11937* $0: Special Parameters. (line 61)
11938* $?: Special Parameters. (line 43)
11939* $@: Special Parameters. (line 23)
11940* $_: Bash Variables. (line 14)
11941* *: Special Parameters. (line 9)
11942* -: Special Parameters. (line 46)
11943* 0: Special Parameters. (line 60)
11944* ?: Special Parameters. (line 42)
11945* @: Special Parameters. (line 22)
11946* _: Bash Variables. (line 13)
11947* active-region-end-color: Readline Init File Syntax.
11948 (line 51)
11949* active-region-start-color: Readline Init File Syntax.
11950 (line 38)
11951* auto_resume: Job Control Variables.
11952 (line 6)
11953* BASH: Bash Variables. (line 23)
11954* BASHOPTS: Bash Variables. (line 26)
11955* BASHPID: Bash Variables. (line 35)
11956* BASH_ALIASES: Bash Variables. (line 42)
11957* BASH_ARGC: Bash Variables. (line 51)
11958* BASH_ARGV: Bash Variables. (line 64)
11959* BASH_ARGV0: Bash Variables. (line 76)
11960* BASH_CMDS: Bash Variables. (line 84)
11961* BASH_COMMAND: Bash Variables. (line 93)
11962* BASH_COMPAT: Bash Variables. (line 100)
11963* BASH_ENV: Bash Variables. (line 116)
11964* BASH_EXECUTION_STRING: Bash Variables. (line 122)
11965* BASH_LINENO: Bash Variables. (line 125)
11966* BASH_LOADABLES_PATH: Bash Variables. (line 133)
11967* BASH_REMATCH: Bash Variables. (line 137)
11968* BASH_SOURCE: Bash Variables. (line 145)
11969* BASH_SUBSHELL: Bash Variables. (line 152)
11970* BASH_VERSINFO: Bash Variables. (line 158)
11971* BASH_VERSION: Bash Variables. (line 181)
11972* BASH_XTRACEFD: Bash Variables. (line 184)
11973* bell-style: Readline Init File Syntax.
11974 (line 64)
11975* bind-tty-special-chars: Readline Init File Syntax.
11976 (line 71)
11977* blink-matching-paren: Readline Init File Syntax.
11978 (line 76)
11979* CDPATH: Bourne Shell Variables.
11980 (line 9)
11981* CHILD_MAX: Bash Variables. (line 195)
11982* colored-completion-prefix: Readline Init File Syntax.
11983 (line 81)
11984* colored-stats: Readline Init File Syntax.
11985 (line 91)
11986* COLUMNS: Bash Variables. (line 202)
11987* comment-begin: Readline Init File Syntax.
11988 (line 97)
11989* completion-display-width: Readline Init File Syntax.
11990 (line 102)
11991* completion-ignore-case: Readline Init File Syntax.
11992 (line 109)
11993* completion-map-case: Readline Init File Syntax.
11994 (line 114)
11995* completion-prefix-display-length: Readline Init File Syntax.
11996 (line 120)
11997* completion-query-items: Readline Init File Syntax.
11998 (line 127)
11999* COMPREPLY: Bash Variables. (line 254)
12000* COMP_CWORD: Bash Variables. (line 208)
12001* COMP_KEY: Bash Variables. (line 237)
12002* COMP_LINE: Bash Variables. (line 214)
12003* COMP_POINT: Bash Variables. (line 219)
12004* COMP_TYPE: Bash Variables. (line 227)
12005* COMP_WORDBREAKS: Bash Variables. (line 241)
12006* COMP_WORDS: Bash Variables. (line 247)
12007* convert-meta: Readline Init File Syntax.
12008 (line 138)
12009* COPROC: Bash Variables. (line 260)
12010* DIRSTACK: Bash Variables. (line 264)
12011* disable-completion: Readline Init File Syntax.
12012 (line 148)
12013* echo-control-characters: Readline Init File Syntax.
12014 (line 153)
12015* editing-mode: Readline Init File Syntax.
12016 (line 158)
12017* EMACS: Bash Variables. (line 274)
12018* emacs-mode-string: Readline Init File Syntax.
12019 (line 164)
12020* enable-active-region: Readline Init File Syntax.
12021 (line 174)
12022* enable-bracketed-paste: Readline Init File Syntax.
12023 (line 187)
12024* enable-keypad: Readline Init File Syntax.
12025 (line 196)
12026* ENV: Bash Variables. (line 279)
12027* EPOCHREALTIME: Bash Variables. (line 284)
12028* EPOCHSECONDS: Bash Variables. (line 292)
12029* EUID: Bash Variables. (line 299)
12030* EXECIGNORE: Bash Variables. (line 303)
12031* expand-tilde: Readline Init File Syntax.
12032 (line 207)
12033* FCEDIT: Bash Variables. (line 316)
12034* FIGNORE: Bash Variables. (line 320)
12035* FUNCNAME: Bash Variables. (line 326)
12036* FUNCNEST: Bash Variables. (line 343)
12037* GLOBIGNORE: Bash Variables. (line 348)
12038* GROUPS: Bash Variables. (line 355)
12039* histchars: Bash Variables. (line 361)
12040* HISTCMD: Bash Variables. (line 376)
12041* HISTCONTROL: Bash Variables. (line 382)
12042* HISTFILE: Bash Variables. (line 398)
12043* HISTFILESIZE: Bash Variables. (line 402)
12044* HISTIGNORE: Bash Variables. (line 413)
12045* history-preserve-point: Readline Init File Syntax.
12046 (line 211)
12047* history-size: Readline Init File Syntax.
12048 (line 217)
12049* HISTSIZE: Bash Variables. (line 433)
12050* HISTTIMEFORMAT: Bash Variables. (line 440)
12051* HOME: Bourne Shell Variables.
12052 (line 13)
12053* horizontal-scroll-mode: Readline Init File Syntax.
12054 (line 226)
12055* HOSTFILE: Bash Variables. (line 448)
12056* HOSTNAME: Bash Variables. (line 459)
12057* HOSTTYPE: Bash Variables. (line 462)
12058* IFS: Bourne Shell Variables.
12059 (line 18)
12060* IGNOREEOF: Bash Variables. (line 465)
12061* input-meta: Readline Init File Syntax.
12062 (line 235)
12063* INPUTRC: Bash Variables. (line 475)
12064* INSIDE_EMACS: Bash Variables. (line 479)
12065* isearch-terminators: Readline Init File Syntax.
12066 (line 245)
12067* keymap: Readline Init File Syntax.
12068 (line 252)
12069* LANG: Creating Internationalized Scripts.
12070 (line 51)
12071* LANG <1>: Bash Variables. (line 485)
12072* LC_ALL: Bash Variables. (line 489)
12073* LC_COLLATE: Bash Variables. (line 493)
12074* LC_CTYPE: Bash Variables. (line 500)
12075* LC_MESSAGES: Creating Internationalized Scripts.
12076 (line 51)
12077* LC_MESSAGES <1>: Bash Variables. (line 505)
12078* LC_NUMERIC: Bash Variables. (line 509)
12079* LC_TIME: Bash Variables. (line 513)
12080* LINENO: Bash Variables. (line 517)
12081* LINES: Bash Variables. (line 522)
12082* MACHTYPE: Bash Variables. (line 528)
12083* MAIL: Bourne Shell Variables.
12084 (line 22)
12085* MAILCHECK: Bash Variables. (line 532)
12086* MAILPATH: Bourne Shell Variables.
12087 (line 27)
12088* MAPFILE: Bash Variables. (line 540)
12089* mark-modified-lines: Readline Init File Syntax.
12090 (line 282)
12091* mark-symlinked-directories: Readline Init File Syntax.
12092 (line 287)
12093* match-hidden-files: Readline Init File Syntax.
12094 (line 292)
12095* menu-complete-display-prefix: Readline Init File Syntax.
12096 (line 299)
12097* meta-flag: Readline Init File Syntax.
12098 (line 235)
12099* OLDPWD: Bash Variables. (line 544)
12100* OPTARG: Bourne Shell Variables.
12101 (line 34)
12102* OPTERR: Bash Variables. (line 547)
12103* OPTIND: Bourne Shell Variables.
12104 (line 38)
12105* OSTYPE: Bash Variables. (line 551)
12106* output-meta: Readline Init File Syntax.
12107 (line 304)
12108* page-completions: Readline Init File Syntax.
12109 (line 312)
12110* PATH: Bourne Shell Variables.
12111 (line 42)
12112* PIPESTATUS: Bash Variables. (line 554)
12113* POSIXLY_CORRECT: Bash Variables. (line 559)
12114* PPID: Bash Variables. (line 569)
12115* PROMPT_COMMAND: Bash Variables. (line 573)
12116* PROMPT_DIRTRIM: Bash Variables. (line 579)
12117* PS0: Bash Variables. (line 585)
12118* PS1: Bourne Shell Variables.
12119 (line 48)
12120* PS2: Bourne Shell Variables.
12121 (line 53)
12122* PS3: Bash Variables. (line 590)
12123* PS4: Bash Variables. (line 595)
12124* PWD: Bash Variables. (line 603)
12125* RANDOM: Bash Variables. (line 606)
12126* READLINE_ARGUMENT: Bash Variables. (line 612)
12127* READLINE_LINE: Bash Variables. (line 616)
12128* READLINE_MARK: Bash Variables. (line 620)
12129* READLINE_POINT: Bash Variables. (line 626)
12130* REPLY: Bash Variables. (line 630)
12131* revert-all-at-newline: Readline Init File Syntax.
12132 (line 322)
12133* SECONDS: Bash Variables. (line 633)
12134* SHELL: Bash Variables. (line 642)
12135* SHELLOPTS: Bash Variables. (line 647)
12136* SHLVL: Bash Variables. (line 656)
12137* show-all-if-ambiguous: Readline Init File Syntax.
12138 (line 329)
12139* show-all-if-unmodified: Readline Init File Syntax.
12140 (line 335)
12141* show-mode-in-prompt: Readline Init File Syntax.
12142 (line 344)
12143* skip-completed-text: Readline Init File Syntax.
12144 (line 350)
12145* SRANDOM: Bash Variables. (line 661)
12146* TEXTDOMAIN: Creating Internationalized Scripts.
12147 (line 51)
12148* TEXTDOMAINDIR: Creating Internationalized Scripts.
12149 (line 51)
12150* TIMEFORMAT: Bash Variables. (line 670)
12151* TMOUT: Bash Variables. (line 708)
12152* TMPDIR: Bash Variables. (line 720)
12153* UID: Bash Variables. (line 724)
12154* vi-cmd-mode-string: Readline Init File Syntax.
12155 (line 363)
12156* vi-ins-mode-string: Readline Init File Syntax.
12157 (line 374)
12158* visible-stats: Readline Init File Syntax.
12159 (line 385)
12160
12161\1f
12162File: bashref.info, Node: Function Index, Next: Concept Index, Prev: Variable Index, Up: Indexes
12163
12164D.4 Function Index
12165==================
12166
12167\0\b[index\0\b]
12168* Menu:
12169
12170* abort (C-g): Miscellaneous Commands.
12171 (line 10)
12172* accept-line (Newline or Return): Commands For History.
12173 (line 6)
12174* alias-expand-line (): Miscellaneous Commands.
12175 (line 131)
12176* backward-char (C-b): Commands For Moving. (line 15)
12177* backward-delete-char (Rubout): Commands For Text. (line 17)
12178* backward-kill-line (C-x Rubout): Commands For Killing.
12179 (line 11)
12180* backward-kill-word (M-<DEL>): Commands For Killing.
12181 (line 28)
12182* backward-word (M-b): Commands For Moving. (line 22)
12183* beginning-of-history (M-<): Commands For History.
12184 (line 20)
12185* beginning-of-line (C-a): Commands For Moving. (line 6)
12186* bracketed-paste-begin (): Commands For Text. (line 33)
12187* call-last-kbd-macro (C-x e): Keyboard Macros. (line 13)
12188* capitalize-word (M-c): Commands For Text. (line 66)
12189* character-search (C-]): Miscellaneous Commands.
12190 (line 42)
12191* character-search-backward (M-C-]): Miscellaneous Commands.
12192 (line 47)
12193* clear-display (M-C-l): Commands For Moving. (line 48)
12194* clear-screen (C-l): Commands For Moving. (line 53)
12195* complete (<TAB>): Commands For Completion.
12196 (line 6)
12197* complete-command (M-!): Commands For Completion.
12198 (line 80)
12199* complete-filename (M-/): Commands For Completion.
12200 (line 49)
12201* complete-hostname (M-@): Commands For Completion.
12202 (line 72)
12203* complete-into-braces (M-{): Commands For Completion.
12204 (line 100)
12205* complete-username (M-~): Commands For Completion.
12206 (line 56)
12207* complete-variable (M-$): Commands For Completion.
12208 (line 64)
12209* copy-backward-word (): Commands For Killing.
12210 (line 69)
12211* copy-forward-word (): Commands For Killing.
12212 (line 74)
12213* copy-region-as-kill (): Commands For Killing.
12214 (line 65)
12215* dabbrev-expand (): Commands For Completion.
12216 (line 95)
12217* delete-char (C-d): Commands For Text. (line 12)
12218* delete-char-or-list (): Commands For Completion.
12219 (line 43)
12220* delete-horizontal-space (): Commands For Killing.
12221 (line 57)
12222* digit-argument (M-0, M-1, ... M--): Numeric Arguments. (line 6)
12223* display-shell-version (C-x C-v): Miscellaneous Commands.
12224 (line 116)
12225* do-lowercase-version (M-A, M-B, M-X, ...): Miscellaneous Commands.
12226 (line 14)
12227* downcase-word (M-l): Commands For Text. (line 62)
12228* dump-functions (): Miscellaneous Commands.
12229 (line 74)
12230* dump-macros (): Miscellaneous Commands.
12231 (line 86)
12232* dump-variables (): Miscellaneous Commands.
12233 (line 80)
12234* dynamic-complete-history (M-<TAB>): Commands For Completion.
12235 (line 90)
12236* edit-and-execute-command (C-x C-e): Miscellaneous Commands.
12237 (line 140)
12238* end-kbd-macro (C-x )): Keyboard Macros. (line 9)
12239* end-of-file (usually C-d): Commands For Text. (line 6)
12240* end-of-history (M->): Commands For History.
12241 (line 23)
12242* end-of-line (C-e): Commands For Moving. (line 9)
12243* exchange-point-and-mark (C-x C-x): Miscellaneous Commands.
12244 (line 37)
12245* fetch-history (): Commands For History.
12246 (line 103)
12247* forward-backward-delete-char (): Commands For Text. (line 21)
12248* forward-char (C-f): Commands For Moving. (line 12)
12249* forward-search-history (C-s): Commands For History.
12250 (line 33)
12251* forward-word (M-f): Commands For Moving. (line 18)
12252* glob-complete-word (M-g): Miscellaneous Commands.
12253 (line 98)
12254* glob-expand-word (C-x *): Miscellaneous Commands.
12255 (line 104)
12256* glob-list-expansions (C-x g): Miscellaneous Commands.
12257 (line 110)
12258* history-and-alias-expand-line (): Miscellaneous Commands.
12259 (line 134)
12260* history-expand-line (M-^): Miscellaneous Commands.
12261 (line 124)
12262* history-search-backward (): Commands For History.
12263 (line 57)
12264* history-search-forward (): Commands For History.
12265 (line 51)
12266* history-substring-search-backward (): Commands For History.
12267 (line 69)
12268* history-substring-search-forward (): Commands For History.
12269 (line 63)
12270* insert-comment (M-#): Miscellaneous Commands.
12271 (line 61)
12272* insert-completions (M-*): Commands For Completion.
12273 (line 22)
12274* insert-last-argument (M-. or M-_): Miscellaneous Commands.
12275 (line 137)
12276* kill-line (C-k): Commands For Killing.
12277 (line 6)
12278* kill-region (): Commands For Killing.
12279 (line 61)
12280* kill-whole-line (): Commands For Killing.
12281 (line 19)
12282* kill-word (M-d): Commands For Killing.
12283 (line 23)
12284* magic-space (): Miscellaneous Commands.
12285 (line 127)
12286* menu-complete (): Commands For Completion.
12287 (line 26)
12288* menu-complete-backward (): Commands For Completion.
12289 (line 38)
12290* next-history (C-n): Commands For History.
12291 (line 17)
12292* next-screen-line (): Commands For Moving. (line 41)
12293* non-incremental-forward-search-history (M-n): Commands For History.
12294 (line 45)
12295* non-incremental-reverse-search-history (M-p): Commands For History.
12296 (line 39)
12297* operate-and-get-next (C-o): Commands For History.
12298 (line 96)
12299* overwrite-mode (): Commands For Text. (line 70)
12300* possible-command-completions (C-x !): Commands For Completion.
12301 (line 86)
12302* possible-completions (M-?): Commands For Completion.
12303 (line 15)
12304* possible-filename-completions (C-x /): Commands For Completion.
12305 (line 52)
12306* possible-hostname-completions (C-x @): Commands For Completion.
12307 (line 76)
12308* possible-username-completions (C-x ~): Commands For Completion.
12309 (line 60)
12310* possible-variable-completions (C-x $): Commands For Completion.
12311 (line 68)
12312* prefix-meta (<ESC>): Miscellaneous Commands.
12313 (line 19)
12314* previous-history (C-p): Commands For History.
12315 (line 13)
12316* previous-screen-line (): Commands For Moving. (line 34)
12317* print-last-kbd-macro (): Keyboard Macros. (line 17)
12318* quoted-insert (C-q or C-v): Commands For Text. (line 26)
12319* re-read-init-file (C-x C-r): Miscellaneous Commands.
12320 (line 6)
12321* redraw-current-line (): Commands For Moving. (line 57)
12322* reverse-search-history (C-r): Commands For History.
12323 (line 27)
12324* revert-line (M-r): Miscellaneous Commands.
12325 (line 26)
12326* self-insert (a, b, A, 1, !, ...): Commands For Text. (line 30)
12327* set-mark (C-@): Miscellaneous Commands.
12328 (line 33)
12329* shell-backward-kill-word (): Commands For Killing.
12330 (line 37)
12331* shell-backward-word (M-C-b): Commands For Moving. (line 30)
12332* shell-expand-line (M-C-e): Miscellaneous Commands.
12333 (line 119)
12334* shell-forward-word (M-C-f): Commands For Moving. (line 26)
12335* shell-kill-word (M-C-d): Commands For Killing.
12336 (line 32)
12337* shell-transpose-words (M-C-t): Commands For Killing.
12338 (line 41)
12339* skip-csi-sequence (): Miscellaneous Commands.
12340 (line 52)
12341* spell-correct-word (C-x s): Miscellaneous Commands.
12342 (line 92)
12343* start-kbd-macro (C-x (): Keyboard Macros. (line 6)
12344* tilde-expand (M-&): Miscellaneous Commands.
12345 (line 30)
12346* transpose-chars (C-t): Commands For Text. (line 47)
12347* transpose-words (M-t): Commands For Text. (line 53)
12348* undo (C-_ or C-x C-u): Miscellaneous Commands.
12349 (line 23)
12350* universal-argument (): Numeric Arguments. (line 10)
12351* unix-filename-rubout (): Commands For Killing.
12352 (line 52)
12353* unix-line-discard (C-u): Commands For Killing.
12354 (line 16)
12355* unix-word-rubout (C-w): Commands For Killing.
12356 (line 48)
12357* upcase-word (M-u): Commands For Text. (line 58)
12358* yank (C-y): Commands For Killing.
12359 (line 79)
12360* yank-last-arg (M-. or M-_): Commands For History.
12361 (line 84)
12362* yank-nth-arg (M-C-y): Commands For History.
12363 (line 75)
12364* yank-pop (M-y): Commands For Killing.
12365 (line 82)
12366
12367\1f
12368File: bashref.info, Node: Concept Index, Prev: Function Index, Up: Indexes
12369
12370D.5 Concept Index
12371=================
12372
12373\0\b[index\0\b]
12374* Menu:
12375
12376* alias expansion: Aliases. (line 6)
12377* arithmetic evaluation: Shell Arithmetic. (line 6)
12378* arithmetic expansion: Arithmetic Expansion.
12379 (line 6)
12380* arithmetic, shell: Shell Arithmetic. (line 6)
12381* arrays: Arrays. (line 6)
12382* background: Job Control Basics. (line 6)
12383* Bash configuration: Basic Installation. (line 6)
12384* Bash installation: Basic Installation. (line 6)
12385* Bourne shell: Basic Shell Features.
12386 (line 6)
12387* brace expansion: Brace Expansion. (line 6)
12388* builtin: Definitions. (line 17)
12389* command editing: Readline Bare Essentials.
12390 (line 6)
12391* command execution: Command Search and Execution.
12392 (line 6)
12393* command expansion: Simple Command Expansion.
12394 (line 6)
12395* command history: Bash History Facilities.
12396 (line 6)
12397* command search: Command Search and Execution.
12398 (line 6)
12399* command substitution: Command Substitution.
12400 (line 6)
12401* command timing: Pipelines. (line 9)
12402* commands, compound: Compound Commands. (line 6)
12403* commands, conditional: Conditional Constructs.
12404 (line 6)
12405* commands, grouping: Command Grouping. (line 6)
12406* commands, lists: Lists. (line 6)
12407* commands, looping: Looping Constructs. (line 6)
12408* commands, pipelines: Pipelines. (line 6)
12409* commands, shell: Shell Commands. (line 6)
12410* commands, simple: Simple Commands. (line 6)
12411* comments, shell: Comments. (line 6)
12412* Compatibility Level: Shell Compatibility Mode.
12413 (line 6)
12414* Compatibility Mode: Shell Compatibility Mode.
12415 (line 6)
12416* completion builtins: Programmable Completion Builtins.
12417 (line 6)
12418* configuration: Basic Installation. (line 6)
12419* control operator: Definitions. (line 21)
12420* coprocess: Coprocesses. (line 6)
12421* directory stack: The Directory Stack. (line 6)
12422* editing command lines: Readline Bare Essentials.
12423 (line 6)
12424* environment: Environment. (line 6)
12425* evaluation, arithmetic: Shell Arithmetic. (line 6)
12426* event designators: Event Designators. (line 6)
12427* execution environment: Command Execution Environment.
12428 (line 6)
12429* exit status: Definitions. (line 26)
12430* exit status <1>: Exit Status. (line 6)
12431* expansion: Shell Expansions. (line 6)
12432* expansion, arithmetic: Arithmetic Expansion.
12433 (line 6)
12434* expansion, brace: Brace Expansion. (line 6)
12435* expansion, filename: Filename Expansion. (line 9)
12436* expansion, parameter: Shell Parameter Expansion.
12437 (line 6)
12438* expansion, pathname: Filename Expansion. (line 9)
12439* expansion, tilde: Tilde Expansion. (line 6)
12440* expressions, arithmetic: Shell Arithmetic. (line 6)
12441* expressions, conditional: Bash Conditional Expressions.
12442 (line 6)
12443* field: Definitions. (line 30)
12444* filename: Definitions. (line 35)
12445* filename expansion: Filename Expansion. (line 9)
12446* foreground: Job Control Basics. (line 6)
12447* functions, shell: Shell Functions. (line 6)
12448* history builtins: Bash History Builtins.
12449 (line 6)
12450* history events: Event Designators. (line 8)
12451* history expansion: History Interaction. (line 6)
12452* history list: Bash History Facilities.
12453 (line 6)
12454* History, how to use: A Programmable Completion Example.
12455 (line 113)
12456* identifier: Definitions. (line 51)
12457* initialization file, readline: Readline Init File. (line 6)
12458* installation: Basic Installation. (line 6)
12459* interaction, readline: Readline Interaction.
12460 (line 6)
12461* interactive shell: Invoking Bash. (line 131)
12462* interactive shell <1>: Interactive Shells. (line 6)
12463* internationalization: Locale Translation. (line 6)
12464* internationalized scripts: Creating Internationalized Scripts.
12465 (line 3)
12466* job: Definitions. (line 38)
12467* job control: Definitions. (line 42)
12468* job control <1>: Job Control Basics. (line 6)
12469* kill ring: Readline Killing Commands.
12470 (line 18)
12471* killing text: Readline Killing Commands.
12472 (line 6)
12473* localization: Locale Translation. (line 6)
12474* login shell: Invoking Bash. (line 128)
12475* matching, pattern: Pattern Matching. (line 6)
12476* metacharacter: Definitions. (line 46)
12477* name: Definitions. (line 51)
12478* native languages: Locale Translation. (line 6)
12479* notation, readline: Readline Bare Essentials.
12480 (line 6)
12481* operator, shell: Definitions. (line 57)
12482* parameter expansion: Shell Parameter Expansion.
12483 (line 6)
12484* parameters: Shell Parameters. (line 6)
12485* parameters, positional: Positional Parameters.
12486 (line 6)
12487* parameters, special: Special Parameters. (line 6)
12488* pathname expansion: Filename Expansion. (line 9)
12489* pattern matching: Pattern Matching. (line 6)
12490* pipeline: Pipelines. (line 6)
12491* POSIX: Definitions. (line 9)
12492* POSIX Mode: Bash POSIX Mode. (line 6)
12493* process group: Definitions. (line 62)
12494* process group ID: Definitions. (line 66)
12495* process substitution: Process Substitution.
12496 (line 6)
12497* programmable completion: Programmable Completion.
12498 (line 6)
12499* prompting: Controlling the Prompt.
12500 (line 6)
12501* quoting: Quoting. (line 6)
12502* quoting, ANSI: ANSI-C Quoting. (line 6)
12503* Readline, how to use: Job Control Variables.
12504 (line 23)
12505* redirection: Redirections. (line 6)
12506* reserved word: Definitions. (line 70)
12507* reserved words: Reserved Words. (line 6)
12508* restricted shell: The Restricted Shell.
12509 (line 6)
12510* return status: Definitions. (line 75)
12511* shell arithmetic: Shell Arithmetic. (line 6)
12512* shell function: Shell Functions. (line 6)
12513* shell script: Shell Scripts. (line 6)
12514* shell variable: Shell Parameters. (line 6)
12515* shell, interactive: Interactive Shells. (line 6)
12516* signal: Definitions. (line 78)
12517* signal handling: Signals. (line 6)
12518* special builtin: Definitions. (line 82)
12519* special builtin <1>: Special Builtins. (line 6)
12520* startup files: Bash Startup Files. (line 6)
12521* string translations: Creating Internationalized Scripts.
12522 (line 3)
12523* suspending jobs: Job Control Basics. (line 6)
12524* tilde expansion: Tilde Expansion. (line 6)
12525* token: Definitions. (line 86)
12526* translation, native languages: Locale Translation. (line 6)
12527* variable, shell: Shell Parameters. (line 6)
12528* variables, readline: Readline Init File Syntax.
12529 (line 37)
12530* word: Definitions. (line 90)
12531* word splitting: Word Splitting. (line 6)
12532* yanking text: Readline Killing Commands.
12533 (line 6)
12534
12535
12536\1f
12537Tag Table:
12538Node: Top\7f899
12539Node: Introduction\7f2821
12540Node: What is Bash?\7f3037
12541Node: What is a shell?\7f4151
12542Node: Definitions\7f6689
12543Node: Basic Shell Features\7f9640
12544Node: Shell Syntax\7f10859
12545Node: Shell Operation\7f11885
12546Node: Quoting\7f13178
12547Node: Escape Character\7f14482
12548Node: Single Quotes\7f14967
12549Node: Double Quotes\7f15315
12550Node: ANSI-C Quoting\7f16593
12551Node: Locale Translation\7f17903
12552Node: Creating Internationalized Scripts\7f19214
12553Node: Comments\7f23331
12554Node: Shell Commands\7f23949
12555Node: Reserved Words\7f24887
12556Node: Simple Commands\7f25643
12557Node: Pipelines\7f26297
12558Node: Lists\7f29296
12559Node: Compound Commands\7f31091
12560Node: Looping Constructs\7f32103
12561Node: Conditional Constructs\7f34598
12562Node: Command Grouping\7f49086
12563Node: Coprocesses\7f50564
12564Node: GNU Parallel\7f53227
12565Node: Shell Functions\7f54144
12566Node: Shell Parameters\7f62029
12567Node: Positional Parameters\7f66417
12568Node: Special Parameters\7f67319
12569Node: Shell Expansions\7f70533
12570Node: Brace Expansion\7f72660
12571Node: Tilde Expansion\7f75394
12572Node: Shell Parameter Expansion\7f78015
12573Node: Command Substitution\7f96366
12574Node: Arithmetic Expansion\7f97721
12575Node: Process Substitution\7f98689
12576Node: Word Splitting\7f99809
12577Node: Filename Expansion\7f101753
12578Node: Pattern Matching\7f104502
12579Node: Quote Removal\7f109504
12580Node: Redirections\7f109799
12581Node: Executing Commands\7f119459
12582Node: Simple Command Expansion\7f120129
12583Node: Command Search and Execution\7f122239
12584Node: Command Execution Environment\7f124617
12585Node: Environment\7f127652
12586Node: Exit Status\7f129315
12587Node: Signals\7f131099
12588Node: Shell Scripts\7f134548
12589Node: Shell Builtin Commands\7f137575
12590Node: Bourne Shell Builtins\7f139613
12591Node: Bash Builtins\7f161079
12592Node: Modifying Shell Behavior\7f191935
12593Node: The Set Builtin\7f192280
12594Node: The Shopt Builtin\7f202881
12595Node: Special Builtins\7f218793
12596Node: Shell Variables\7f219772
12597Node: Bourne Shell Variables\7f220209
12598Node: Bash Variables\7f222313
12599Node: Bash Features\7f255128
12600Node: Invoking Bash\7f256141
12601Node: Bash Startup Files\7f262154
12602Node: Interactive Shells\7f267285
12603Node: What is an Interactive Shell?\7f267696
12604Node: Is this Shell Interactive?\7f268345
12605Node: Interactive Shell Behavior\7f269160
12606Node: Bash Conditional Expressions\7f272789
12607Node: Shell Arithmetic\7f277431
12608Node: Aliases\7f280375
12609Node: Arrays\7f282988
12610Node: The Directory Stack\7f289379
12611Node: Directory Stack Builtins\7f290163
12612Node: Controlling the Prompt\7f294423
12613Node: The Restricted Shell\7f297388
12614Node: Bash POSIX Mode\7f299998
12615Node: Shell Compatibility Mode\7f311916
12616Node: Job Control\7f320483
12617Node: Job Control Basics\7f320943
12618Node: Job Control Builtins\7f325945
12619Node: Job Control Variables\7f331740
12620Node: Command Line Editing\7f332896
12621Node: Introduction and Notation\7f334567
12622Node: Readline Interaction\7f336190
12623Node: Readline Bare Essentials\7f337381
12624Node: Readline Movement Commands\7f339170
12625Node: Readline Killing Commands\7f340130
12626Node: Readline Arguments\7f342051
12627Node: Searching\7f343095
12628Node: Readline Init File\7f345281
12629Node: Readline Init File Syntax\7f346542
12630Node: Conditional Init Constructs\7f370128
12631Node: Sample Init File\7f374324
12632Node: Bindable Readline Commands\7f377448
12633Node: Commands For Moving\7f378652
12634Node: Commands For History\7f380703
12635Node: Commands For Text\7f385697
12636Node: Commands For Killing\7f389346
12637Node: Numeric Arguments\7f392379
12638Node: Commands For Completion\7f393518
12639Node: Keyboard Macros\7f397709
12640Node: Miscellaneous Commands\7f398397
12641Node: Readline vi Mode\7f404342
12642Node: Programmable Completion\7f405249
12643Node: Programmable Completion Builtins\7f413029
12644Node: A Programmable Completion Example\7f423781
12645Node: Using History Interactively\7f429029
12646Node: Bash History Facilities\7f429713
12647Node: Bash History Builtins\7f432718
12648Node: History Interaction\7f437742
12649Node: Event Designators\7f441362
12650Node: Word Designators\7f442716
12651Node: Modifiers\7f444476
12652Node: Installing Bash\7f446284
12653Node: Basic Installation\7f447421
12654Node: Compilers and Options\7f451143
12655Node: Compiling For Multiple Architectures\7f451884
12656Node: Installation Names\7f453576
12657Node: Specifying the System Type\7f455685
12658Node: Sharing Defaults\7f456402
12659Node: Operation Controls\7f457075
12660Node: Optional Features\7f458033
12661Node: Reporting Bugs\7f469252
12662Node: Major Differences From The Bourne Shell\7f470527
12663Node: GNU Free Documentation License\7f487376
12664Node: Indexes\7f512553
12665Node: Builtin Index\7f513007
12666Node: Reserved Word Index\7f519834
12667Node: Variable Index\7f522282
12668Node: Function Index\7f539056
12669Node: Concept Index\7f552840
12670\1f
12671End Tag Table
12672
12673\1f
12674Local Variables:
12675coding: utf-8
12676End: