]> git.ipfire.org Git - thirdparty/bash.git/blame - doc/bash.html
updated translations; remove unneeded files
[thirdparty/bash.git] / doc / bash.html
CommitLineData
17345e5a
JA
1<HTML><HEAD>
2<TITLE>BASH(1) Manual Page</TITLE>
3</HEAD>
4<BODY><TABLE WIDTH=100%>
5<TR>
74091dd4 6<TH ALIGN=LEFT width=33%>BASH(1)<TH ALIGN=CENTER width=33%>2022 September 19<TH ALIGN=RIGHT width=33%>BASH(1)
17345e5a
JA
7</TR>
8</TABLE>
9<BR><A HREF="#index">Index</A>
10<HR>
11
12
13
14
15
16
17
18
19
20
d233b485
CR
21
22
23
24
25
26
27
28
29
30
31
32
17345e5a
JA
33
34
35
36
37
38
39
40
41
42<A NAME="lbAB">&nbsp;</A>
43<H3>NAME</H3>
44
45bash - GNU Bourne-Again SHell
46<A NAME="lbAC">&nbsp;</A>
47<H3>SYNOPSIS</H3>
48
49<B>bash</B>
50
51[options]
ac50fbac 52[command_string | file]
17345e5a
JA
53<A NAME="lbAD">&nbsp;</A>
54<H3>COPYRIGHT</H3>
55
56
74091dd4 57Bash is Copyright &#169; 1989-2022 by the Free Software Foundation, Inc.
17345e5a
JA
58<A NAME="lbAE">&nbsp;</A>
59<H3>DESCRIPTION</H3>
60
61<B>Bash</B>
62
63is an <B>sh</B>-compatible command language interpreter that
64executes commands read from the standard input or from a file.
65<B>Bash</B>
66
67also incorporates useful features from the <I>Korn</I> and <I>C</I>
68shells (<B>ksh</B> and <B>csh</B>).
69<P>
70
71<B>Bash</B>
72
73is intended to be a conformant implementation of the
74Shell and Utilities portion of the IEEE POSIX specification
75(IEEE Standard 1003.1).
76<B>Bash</B>
77
78can be configured to be POSIX-conformant by default.
79<A NAME="lbAF">&nbsp;</A>
80<H3>OPTIONS</H3>
81
a0c0a00f 82All of the single-character shell options documented in the
d233b485
CR
83description of the <B>set</B> builtin command, including <B>-o</B>,
84can be used as options when the shell is invoked.
495aee44 85In addition, <B>bash</B>
17345e5a
JA
86interprets the following options when it is invoked:
87<P>
88
89
90<DL COMPACT>
ac50fbac 91<DT><B>-c</B>
17345e5a
JA
92
93<DD>
94If the
95<B>-c</B>
96
ac50fbac
CR
97option is present, then commands are read from the first non-option argument
98<I>command_string</I>.
17345e5a
JA
99
100If there are arguments after the
ac50fbac 101<I>command_string</I>,
17345e5a 102
a0c0a00f
CR
103the first argument is assigned to
104<B>$0</B>
105
106and any remaining arguments are assigned to the positional parameters.
107The assignment to
108<B>$0</B>
17345e5a 109
a0c0a00f 110sets the name of the shell, which is used in warning and error messages.
17345e5a
JA
111<DT><B>-i</B>
112
113<DD>
114If the
115<B>-i</B>
116
117option is present, the shell is
118<I>interactive</I>.
119
120<DT><B>-l</B>
121
122<DD>
123Make
124<B>bash</B>
125
126act as if it had been invoked as a login shell (see
127<FONT SIZE=-1><B>INVOCATION</B>
128
129</FONT>
130below).
131<DT><B>-r</B>
132
133<DD>
134If the
135<B>-r</B>
136
137option is present, the shell becomes
138<I>restricted</I>
139
140(see
141<FONT SIZE=-1><B>RESTRICTED SHELL</B>
142
143</FONT>
144below).
145<DT><B>-s</B>
146
147<DD>
148If the
149<B>-s</B>
150
151option is present, or if no arguments remain after option
152processing, then commands are read from the standard input.
153This option allows the positional parameters to be set
d233b485
CR
154when invoking an interactive shell or when reading input
155through a pipe.
17345e5a
JA
156<DT><B>-D</B>
157
158<DD>
159A list of all double-quoted strings preceded by <B>$</B>
160is printed on the standard output.
161These are the strings that
162are subject to language translation when the current locale
163is not <B>C</B> or <B>POSIX</B>.
164This implies the <B>-n</B> option; no commands will be executed.
165<DT><B>[-+]O [</B><I>shopt_option</I>]
166
167<DD>
168<I>shopt_option</I> is one of the shell options accepted by the
169<B>shopt</B> builtin (see
170<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
171
172</FONT>
173below).
174If <I>shopt_option</I> is present, <B>-O</B> sets the value of that option;
175<B>+O</B> unsets it.
176If <I>shopt_option</I> is not supplied, the names and values of the shell
177options accepted by <B>shopt</B> are printed on the standard output.
178If the invocation option is <B>+O</B>, the output is displayed in a format
179that may be reused as input.
180<DT><B>--</B>
181
182<DD>
183A
184<B>--</B>
185
186signals the end of options and disables further option processing.
187Any arguments after the
188<B>--</B>
189
190are treated as filenames and arguments. An argument of
191<B>-</B>
192
193is equivalent to <B>--</B>.
194
195</DL>
196<P>
197
198<B>Bash</B>
199
200also interprets a number of multi-character options.
201These options must appear on the command line before the
202single-character options to be recognized.
203<P>
204
205
206<DL COMPACT>
207<DT><B>--debugger</B>
208
209<DD>
210Arrange for the debugger profile to be executed before the shell
211starts.
212Turns on extended debugging mode (see the description of the
213<B>extdebug</B>
214
215option to the
216<B>shopt</B>
217
17345e5a
JA
218builtin below).
219<DT><B>--dump-po-strings</B>
220
221<DD>
222Equivalent to <B>-D</B>, but the output is in the GNU <I>gettext</I>
223<B>po</B> (portable object) file format.
224<DT><B>--dump-strings</B>
225
226<DD>
227Equivalent to <B>-D</B>.
228<DT><B>--help</B>
229
230<DD>
231Display a usage message on standard output and exit successfully.
232<DT><B>--init-file</B> <I>file</I><DD>
233
234<DT><B>--rcfile</B> <I>file</I><DD>
235
236Execute commands from
237<I>file</I>
238
239instead of the standard personal initialization file
240<A HREF="file:~/.bashrc"><I>~/.bashrc</I></A>
241
242if the shell is interactive (see
243<FONT SIZE=-1><B>INVOCATION</B>
244
245</FONT>
246below).
247<DT><B>--login</B>
248
249<DD>
250Equivalent to <B>-l</B>.
251<DT><B>--noediting</B>
252
253<DD>
254Do not use the GNU
255<B>readline</B>
256
257library to read command lines when the shell is interactive.
258<DT><B>--noprofile</B>
259
260<DD>
261Do not read either the system-wide startup file
262
263<A HREF="file:/etc/profile"><I>/etc/profile</I></A>
264
265or any of the personal initialization files
266<A HREF="file:~/.bash_profile"><I>~/.bash_profile</I></A>,
267
268<A HREF="file:~/.bash_login"><I>~/.bash_login</I></A>,
269
270or
271<A HREF="file:~/.profile"><I>~/.profile</I></A>.
272
273By default,
274<B>bash</B>
275
276reads these files when it is invoked as a login shell (see
277<FONT SIZE=-1><B>INVOCATION</B>
278
279</FONT>
280below).
281<DT><B>--norc</B>
282
283<DD>
284Do not read and execute the personal initialization file
285<A HREF="file:~/.bashrc"><I>~/.bashrc</I></A>
286
287if the shell is interactive.
288This option is on by default if the shell is invoked as
289<B>sh</B>.
290
291<DT><B>--posix</B>
292
293<DD>
294Change the behavior of <B>bash</B> where the default operation differs
295from the POSIX standard to match the standard (<I>posix mode</I>).
ac50fbac
CR
296See
297<FONT SIZE=-1><B>SEE ALSO</B>
298
299</FONT>
300below for a reference to a document that details how posix mode affects
301bash's behavior.
17345e5a
JA
302<DT><B>--restricted</B>
303
304<DD>
305The shell becomes restricted (see
306<FONT SIZE=-1><B>RESTRICTED SHELL</B>
307
308</FONT>
309below).
310<DT><B>--verbose</B>
311
312<DD>
a0c0a00f 313Equivalent to <B>-v</B>.
17345e5a
JA
314<DT><B>--version</B>
315
316<DD>
317Show version information for this instance of
318<B>bash</B>
319
320on the standard output and exit successfully.
321
322</DL>
323<A NAME="lbAG">&nbsp;</A>
324<H3>ARGUMENTS</H3>
325
326If arguments remain after option processing, and neither the
327<B>-c</B>
328
329nor the
330<B>-s</B>
331
332option has been supplied, the first argument is assumed to
333be the name of a file containing shell commands.
334If
335<B>bash</B>
336
a0c0a00f 337is invoked in this fashion,
17345e5a
JA
338<B>$0</B>
339
340is set to the name of the file, and the positional parameters
341are set to the remaining arguments.
342<B>Bash</B>
343
344reads and executes commands from this file, then exits.
345<B>Bash</B>'s exit status is the exit status of the last command
346executed in the script.
347If no commands are executed, the exit status is 0.
348An attempt is first made to open the file in the current directory, and,
349if no file is found, then the shell searches the directories in
350<FONT SIZE=-1><B>PATH</B>
351
352</FONT>
353for the script.
354<A NAME="lbAH">&nbsp;</A>
355<H3>INVOCATION</H3>
356
357A <I>login shell</I> is one whose first character of argument zero is a
358<B>-</B>,
359
a0c0a00f 360or one started with the
17345e5a
JA
361<B>--login</B>
362
363option.
364<P>
365
366An <I>interactive</I> shell is one started without non-option arguments
a0c0a00f 367(unless <B>-s</B> is specified)
17345e5a
JA
368and without the
369<B>-c</B>
370
74091dd4 371option,
17345e5a
JA
372whose standard input and error are
373both connected to terminals (as determined by
374<I>isatty</I>(3)),
375
376or one started with the
377<B>-i</B>
378
379option.
380<FONT SIZE=-1><B>PS1</B>
381
382</FONT>
383is set and
384<B>$-</B>
385
386includes
387<B>i</B>
388
389if
390<B>bash</B>
391
392is interactive,
393allowing a shell script or a startup file to test this state.
394<P>
395
396The following paragraphs describe how
397<B>bash</B>
398
399executes its startup files.
400If any of the files exist but cannot be read,
401<B>bash</B>
402
403reports an error.
ac50fbac 404Tildes are expanded in filenames as described below under
17345e5a
JA
405<B>Tilde Expansion</B>
406
407in the
408<FONT SIZE=-1><B>EXPANSION</B>
409
410</FONT>
411section.
412<P>
413
414When
415<B>bash</B>
416
417is invoked as an interactive login shell, or as a non-interactive shell
418with the <B>--login</B> option, it first reads and
419executes commands from the file <A HREF="file:/etc/profile"><I>/etc/profile</I></A>, if that
420file exists.
421After reading that file, it looks for <A HREF="file:~/.bash_profile"><I>~/.bash_profile</I></A>,
422<A HREF="file:~/.bash_login"><I>~/.bash_login</I></A>, and <A HREF="file:~/.profile"><I>~/.profile</I></A>, in that order, and reads
423and executes commands from the first one that exists and is readable.
424The
425<B>--noprofile</B>
426
427option may be used when the shell is started to inhibit this behavior.
428<P>
429
a0c0a00f
CR
430When an interactive login shell exits,
431or a non-interactive login shell executes the <B>exit</B> builtin command,
17345e5a
JA
432<B>bash</B>
433
434reads and executes commands from the file <A HREF="file:~/.bash_logout"><I>~/.bash_logout</I></A>, if it
435exists.
436<P>
437
438When an interactive shell that is not a login shell is started,
439<B>bash</B>
440
441reads and executes commands from <A HREF="file:~/.bashrc"><I>~/.bashrc</I></A>, if that file exists.
442This may be inhibited by using the
443<B>--norc</B>
444
445option.
446The <B>--rcfile</B> <I>file</I> option will force
447<B>bash</B>
448
449to read and execute commands from <I>file</I> instead of <A HREF="file:~/.bashrc"><I>~/.bashrc</I></A>.
450<P>
451
452When
453<B>bash</B>
454
455is started non-interactively, to run a shell script, for example, it
456looks for the variable
457<FONT SIZE=-1><B>BASH_ENV</B>
458
459</FONT>
460in the environment, expands its value if it appears there, and uses the
461expanded value as the name of a file to read and execute.
462<B>Bash</B>
463
464behaves as if the following command were executed:
465<P>
466<DL COMPACT><DT><DD>
467<TT>if [ -n &quot;$BASH_ENV&quot; ]; then . &quot;$BASH_ENV&quot;; fi</TT>
468
469</DL>
470
471<P>
472but the value of the
473<FONT SIZE=-1><B>PATH</B>
474
475</FONT>
ac50fbac 476variable is not used to search for the filename.
17345e5a
JA
477<P>
478
479If
480<B>bash</B>
481
482is invoked with the name
483<B>sh</B>,
484
485it tries to mimic the startup behavior of historical versions of
486<B>sh</B>
487
488as closely as possible,
489while conforming to the POSIX standard as well.
490When invoked as an interactive login shell, or a non-interactive
491shell with the <B>--login</B> option, it first attempts to
492read and execute commands from
493<A HREF="file:/etc/profile"><I>/etc/profile</I></A>
494
495and
496<A HREF="file:~/.profile"><I>~/.profile</I></A>,
497
498in that order.
499The
500<B>--noprofile</B>
501
502option may be used to inhibit this behavior.
503When invoked as an interactive shell with the name
504<B>sh</B>,
505
506<B>bash</B>
507
508looks for the variable
509<FONT SIZE=-1><B>ENV</B>,
510
511</FONT>
512expands its value if it is defined, and uses the
513expanded value as the name of a file to read and execute.
514Since a shell invoked as
515<B>sh</B>
516
517does not attempt to read and execute commands from any other startup
518files, the
519<B>--rcfile</B>
520
521option has no effect.
522A non-interactive shell invoked with the name
523<B>sh</B>
524
8868edaf 525does not attempt to read any other startup files.
17345e5a
JA
526When invoked as
527<B>sh</B>,
528
529<B>bash</B>
530
531enters
532<I>posix</I>
533
534mode after the startup files are read.
535<P>
536
537When
538<B>bash</B>
539
540is started in
541<I>posix</I>
542
543mode, as with the
544<B>--posix</B>
545
546command line option, it follows the POSIX standard for startup files.
547In this mode, interactive shells expand the
548<FONT SIZE=-1><B>ENV</B>
549
550</FONT>
551variable and commands are read and executed from the file
552whose name is the expanded value.
553No other startup files are read.
554<P>
555
556<B>Bash</B>
557
558attempts to determine when it is being run with its standard input
74091dd4
CR
559connected to a network connection, as when executed by
560the historical remote shell daemon, usually <I>rshd</I>,
561or the secure shell daemon <I>sshd</I>.
17345e5a
JA
562If
563<B>bash</B>
564
74091dd4
CR
565determines it is being run non-interactively in this fashion,
566it reads and executes commands from <A HREF="file:~/.bashrc"><I>~/.bashrc</I></A>,
567if that file exists and is readable.
17345e5a
JA
568It will not do this if invoked as <B>sh</B>.
569The
570<B>--norc</B>
571
572option may be used to inhibit this behavior, and the
573<B>--rcfile</B>
574
ac50fbac
CR
575option may be used to force another file to be read, but neither
576<I>rshd</I> nor <I>sshd</I> generally invoke the shell with those options
17345e5a
JA
577or allow them to be specified.
578<P>
579
580If the shell is started with the effective user (group) id not equal to the
581real user (group) id, and the <B>-p</B> option is not supplied, no startup
582files are read, shell functions are not inherited from the environment, the
0001803f
CR
583<FONT SIZE=-1><B>SHELLOPTS</B>,
584
585</FONT>
586<FONT SIZE=-1><B>BASHOPTS</B>,
587
588</FONT>
589<FONT SIZE=-1><B>CDPATH</B>,
17345e5a
JA
590
591</FONT>
0001803f
CR
592and
593<FONT SIZE=-1><B>GLOBIGNORE</B>
594
595</FONT>
596variables, if they appear in the environment, are ignored,
17345e5a
JA
597and the effective user id is set to the real user id.
598If the <B>-p</B> option is supplied at invocation, the startup behavior is
599the same, but the effective user id is not reset.
600<A NAME="lbAI">&nbsp;</A>
601<H3>DEFINITIONS</H3>
602
17345e5a
JA
603The following definitions are used throughout the rest of this
604document.
605
606<DL COMPACT>
a0c0a00f 607<DT><B>blank</B>
17345e5a
JA
608
609<DD>
610A space or tab.
611<DT><B>word</B>
612
613<DD>
614A sequence of characters considered as a single unit by the shell.
615Also known as a
616<B>token</B>.
617
618<DT><B>name</B>
619
620<DD>
a0c0a00f 621A
17345e5a
JA
622<I>word</I>
623
624consisting only of alphanumeric characters and underscores, and
625beginning with an alphabetic character or an underscore. Also
626referred to as an
627<B>identifier</B>.
628
629<DT><B>metacharacter</B>
630
631<DD>
632A character that, when unquoted, separates words. One of the following:
633<BR>
634
635<DL COMPACT><DT><DD>
636<P>
637
a0c0a00f 638<B>| &amp; ; ( ) &lt; &gt; space tab newline</B>
17345e5a
JA
639
640</DL>
641
17345e5a
JA
642<DT><B>control operator</B>
643
644<DD>
645A <I>token</I> that performs a control function. It is one of the following
646symbols:
647<DL COMPACT><DT><DD>
648<P>
649
a0c0a00f 650<B>|| &amp; &amp;&amp; ; ;; ;&amp; ;;&amp; ( ) | |&amp; &lt;newline&gt;</B>
17345e5a
JA
651
652</DL>
653
654
655</DL>
656<A NAME="lbAJ">&nbsp;</A>
657<H3>RESERVED WORDS</H3>
658
659<I>Reserved words</I> are words that have a special meaning to the shell.
660The following words are recognized as reserved when unquoted and either
8868edaf 661the first word of a command (see
17345e5a
JA
662<FONT SIZE=-1><B>SHELL GRAMMAR</B>
663
664</FONT>
8868edaf 665below), the third word of a
a0c0a00f 666<B>case</B>
17345e5a
JA
667
668or
8868edaf
CR
669<B>select</B>
670
671command
672(only <B>in</B> is valid), or the third word of a
17345e5a
JA
673<B>for</B>
674
8868edaf 675command (only <B>in</B> and <B>do</B> are valid):
17345e5a
JA
676<DL COMPACT><DT><DD>
677
678<P>
679
680<B>
681</B>
682
ac50fbac 683! case coproc do done elif else esac fi for function if in select then until while { } time [[ ]]
17345e5a
JA
684</DL>
685
686
687<A NAME="lbAK">&nbsp;</A>
688<H3>SHELL GRAMMAR</H3>
689
74091dd4 690This section describes the syntax of the various forms of shell commands.
17345e5a
JA
691<A NAME="lbAL">&nbsp;</A>
692<H4>Simple Commands</H4>
693
17345e5a
JA
694A <I>simple command</I> is a sequence of optional variable assignments
695followed by <B>blank</B>-separated words and redirections, and
696terminated by a <I>control operator</I>. The first word
697specifies the command to be executed, and is passed as argument zero.
698The remaining words are passed as arguments to the invoked command.
699<P>
700
701The return value of a <I>simple command</I> is its exit status, or
702128+<I>n</I> if the command is terminated by signal
703<I>n</I>.
704
705<A NAME="lbAM">&nbsp;</A>
706<H4>Pipelines</H4>
707
17345e5a
JA
708A <I>pipeline</I> is a sequence of one or more commands separated by
709one of the control operators
710<B>|</B>
711
712or <B>|&amp;</B>.
713The format for a pipeline is:
714<DL COMPACT><DT><DD>
715<P>
716
74091dd4 717[<B>time</B> [<B>-p</B>]] [ ! ] <I>command1</I> [ [<B>|</B>|<B>|&amp;</B>] <I>command2</I> ... ]
17345e5a
JA
718</DL>
719
720<P>
721
722The standard output of
74091dd4 723<I>command1</I>
17345e5a
JA
724
725is connected via a pipe to the standard input of
726<I>command2</I>.
727
728This connection is performed before any redirections specified by the
74091dd4
CR
729<I>command1</I>(see
730
17345e5a
JA
731<FONT SIZE=-1><B>REDIRECTION</B>
732
733</FONT>
734below).
74091dd4 735If <B>|&amp;</B> is used, <I>command1</I>'s standard error, in addition to its
ac50fbac
CR
736standard output, is connected to
737<I>command2</I>'s standard input through the pipe;
738it is shorthand for <B>2&gt;&amp;1 |</B>.
739This implicit redirection of the standard error to the standard output is
74091dd4 740performed after any redirections specified by <I>command1</I>.
17345e5a
JA
741<P>
742
743The return status of a pipeline is the exit status of the last
744command, unless the <B>pipefail</B> option is enabled.
745If <B>pipefail</B> is enabled, the pipeline's return status is the
746value of the last (rightmost) command to exit with a non-zero status,
747or zero if all commands exit successfully.
748If the reserved word
749<B>!</B>
750
751precedes a pipeline, the exit status of that pipeline is the logical
752negation of the exit status as described above.
753The shell waits for all commands in the pipeline to
754terminate before returning a value.
755<P>
756
757If the
758<B>time</B>
759
760reserved word precedes a pipeline, the elapsed as well as user and
761system time consumed by its execution are reported when the pipeline
762terminates.
763The <B>-p</B> option changes the output format to that specified by POSIX.
495aee44
CR
764When the shell is in <I>posix mode</I>, it does not recognize
765<B>time</B> as a reserved word if the next token begins with a `-'.
17345e5a
JA
766The
767<FONT SIZE=-1><B>TIMEFORMAT</B>
768
769</FONT>
770variable may be set to a format string that specifies how the timing
771information should be displayed; see the description of
772<FONT SIZE=-1><B>TIMEFORMAT</B>
773
774</FONT>
775under
776<B>Shell Variables</B>
777
778below.
779<P>
780
495aee44
CR
781When the shell is in <I>posix mode</I>, <B>time</B>
782may be followed by a newline. In this case, the shell displays the
783total user and system time consumed by the shell and its children.
784The
785<FONT SIZE=-1><B>TIMEFORMAT</B>
786
787</FONT>
788variable may be used to specify the format of
789the time information.
790<P>
791
74091dd4
CR
792Each command in a multi-command pipeline,
793where pipes are created,
794is executed in a <I>subshell</I>, which is a
795separate process.
d233b485
CR
796See
797<FONT SIZE=-1><B>COMMAND EXECUTION ENVIRONMENT</B></FONT>
74091dd4 798for a description of subshells and a subshell environment.
d233b485
CR
799If the <B>lastpipe</B> option is enabled using the <B>shopt</B> builtin
800(see the description of <B>shopt</B> below),
74091dd4
CR
801the last element of a pipeline may be run by the shell process
802when job control is not active.
17345e5a
JA
803<A NAME="lbAN">&nbsp;</A>
804<H4>Lists</H4>
805
17345e5a
JA
806A <I>list</I> is a sequence of one or more pipelines separated by one
807of the operators
808<B>;</B>,
809
810<B>&amp;</B>,
811
812<B>&amp;&amp;</B>,
813
814or
815<B>||</B>,
816
817and optionally terminated by one of
818<B>;</B>,
819
820<B>&amp;</B>,
821
822or
823<B>&lt;newline&gt;</B>.
824
825<P>
826
827Of these list operators,
828<B>&amp;&amp;</B>
829
830and
831<B>||</B>
832
833have equal precedence, followed by
834<B>;</B>
835
836and
837<B>&amp;</B>,
838
839which have equal precedence.
840<P>
841
842A sequence of one or more newlines may appear in a <I>list</I> instead
843of a semicolon to delimit commands.
844<P>
845
846If a command is terminated by the control operator
847<B>&amp;</B>,
848
849the shell executes the command in the <I>background</I>
d233b485
CR
850in a subshell.
851The shell does not wait for the command to
852finish, and the return status is 0.
853These are referred to as <I>asynchronous</I> commands.
854Commands separated by a
17345e5a
JA
855<B>;</B>
856
857are executed sequentially; the shell waits for each
858command to terminate in turn. The return status is the
859exit status of the last command executed.
860<P>
861
a0c0a00f 862AND and OR lists are sequences of one or more pipelines separated by the
17345e5a
JA
863<B>&amp;&amp;</B> and <B>||</B> control operators, respectively.
864AND and OR lists are executed with left associativity.
865An AND list has the form
866<DL COMPACT><DT><DD>
867<P>
868
869<I>command1</I> <B>&amp;&amp;</B> <I>command2</I>
870</DL>
871
872<P>
873
874<I>command2</I>
875
876is executed if, and only if,
877<I>command1</I>
878
d233b485 879returns an exit status of zero (success).
17345e5a
JA
880<P>
881
882An OR list has the form
883<DL COMPACT><DT><DD>
884<P>
885
886<I>command1</I> <B>||</B> <I>command2</I>
17345e5a
JA
887</DL>
888
889<P>
890
891<I>command2</I>
892
d233b485 893is executed if, and only if,
17345e5a
JA
894<I>command1</I>
895
896returns a non-zero exit status.
897The return status of
898AND and OR lists is the exit status of the last command
899executed in the list.
900<A NAME="lbAO">&nbsp;</A>
901<H4>Compound Commands</H4>
902
ac50fbac
CR
903A <I>compound command</I> is one of the following.
904In most cases a <I>list</I> in a command's description may be separated from
905the rest of the command by one or more newlines, and may be followed by a
906newline in place of a semicolon.
17345e5a
JA
907<DL COMPACT>
908<DT>(<I>list</I>)<DD>
74091dd4 909<I>list</I> is executed in a subshell (see
17345e5a 910<FONT SIZE=-1><B>COMMAND EXECUTION ENVIRONMENT</B></FONT>
74091dd4 911below for a description of a subshell environment).
17345e5a
JA
912Variable assignments and builtin
913commands that affect the shell's environment do not remain in effect
914after the command completes. The return status is the exit status of
915<I>list</I>.
916<DT>{ <I>list</I>; }<DD>
917<I>list</I> is simply executed in the current shell environment.
918<I>list</I> must be terminated with a newline or semicolon.
919This is known as a <I>group command</I>.
920The return status is the exit status of
921<I>list</I>.
922Note that unlike the metacharacters <B>(</B> and <B>)</B>, <B>{</B> and
923<B>}</B> are <I>reserved words</I> and must occur where a reserved
924word is permitted to be recognized. Since they do not cause a word
925break, they must be separated from <I>list</I> by whitespace or another
926shell metacharacter.
927<DT>((<I>expression</I>))<DD>
928The <I>expression</I> is evaluated according to the rules described
929below under
930<FONT SIZE=-1><B>ARITHMETIC EVALUATION</B>.
931
932</FONT>
933If the value of the expression is non-zero, the return status is 0;
74091dd4
CR
934otherwise the return status is 1.
935The <I>expression</I>
936undergoes the same expansions
937as if it were within double quotes,
938but double quote characters in <I>expression</I> are not treated specially
939and are removed.
17345e5a
JA
940<DT><B>[[</B> <I>expression</I> <B>]]</B><DD>
941Return a status of 0 or 1 depending on the evaluation of
942the conditional expression <I>expression</I>.
943Expressions are composed of the primaries described below under
944<FONT SIZE=-1><B>CONDITIONAL EXPRESSIONS</B>.
945
946</FONT>
74091dd4
CR
947The words between the <B>[[</B> and <B>]]</B> do not undergo word splitting
948and pathname expansion.
949The shell performs tilde expansion, parameter and
950variable expansion, arithmetic expansion, command substitution, process
951substitution, and quote removal on those words
952(the expansions that would occur if the words were enclosed in double quotes).
17345e5a
JA
953Conditional operators such as <B>-f</B> must be unquoted to be recognized
954as primaries.
955<P>
956
957
495aee44 958When used with <B>[[</B>, the <B>&lt;</B> and <B>&gt;</B> operators sort
0001803f
CR
959lexicographically using the current locale.
960<P>
961
962
17345e5a
JA
963When the <B>==</B> and <B>!=</B> operators are used, the string to the
964right of the operator is considered a pattern and matched according
ac50fbac
CR
965to the rules described below under <B>Pattern Matching</B>,
966as if the <B>extglob</B> shell option were enabled.
967The <B>=</B> operator is equivalent to <B>==</B>.
a0c0a00f 968If the
17345e5a
JA
969<B>nocasematch</B>
970
a0c0a00f 971shell option is enabled, the match is performed without regard to the case
17345e5a
JA
972of alphabetic characters.
973The return value is 0 if the string matches (<B>==</B>) or does not match
974(<B>!=</B>) the pattern, and 1 otherwise.
ac50fbac
CR
975Any part of the pattern may be quoted to force the quoted portion
976to be matched as a string.
17345e5a
JA
977<P>
978
979
980An additional binary operator, <B>=~</B>, is available, with the same
981precedence as <B>==</B> and <B>!=</B>.
982When it is used, the string to the right of the operator is considered
8868edaf
CR
983a POSIX extended regular expression and matched accordingly
984(using the POSIX <I>regcomp</I> and <I>regexec</I> interfaces
985usually described in <I>regex</I>(3)).
17345e5a
JA
986The return value is 0 if the string matches
987the pattern, and 1 otherwise.
988If the regular expression is syntactically incorrect, the conditional
989expression's return value is 2.
a0c0a00f 990If the
17345e5a
JA
991<B>nocasematch</B>
992
a0c0a00f 993shell option is enabled, the match is performed without regard to the case
17345e5a 994of alphabetic characters.
74091dd4
CR
995If any part of the pattern is quoted, the quoted portion is matched literally.
996This means every character in the quoted portion matches itself,
997instead of having any special pattern matching meaning.
ac50fbac 998If the pattern is stored in a shell variable, quoting the variable
74091dd4
CR
999expansion forces the entire pattern to be matched literally.
1000Treat bracket expressions in regular expressions carefully,
1001since normal quoting and pattern characters lose their meanings
1002between brackets.
8868edaf
CR
1003<P>
1004
1005
1006The pattern will match if it matches any part of the string.
1007Anchor the pattern using the <B>^</B> and <B>$</B> regular expression
1008operators to force it to match the entire string.
1009The array variable
1010<FONT SIZE=-1><B>BASH_REMATCH</B>
0001803f
CR
1011
1012</FONT>
8868edaf 1013records which parts of the string matched the pattern.
0001803f
CR
1014The element of
1015<FONT SIZE=-1><B>BASH_REMATCH</B>
1016
1017</FONT>
8868edaf
CR
1018with index 0 contains the portion of
1019the string matching the entire regular expression.
1020Substrings matched by parenthesized subexpressions within the regular
1021expression are saved in the remaining
1022<FONT SIZE=-1><B>BASH_REMATCH</B>
1023
1024</FONT>
1025indices. The element of
0001803f
CR
1026<FONT SIZE=-1><B>BASH_REMATCH</B>
1027
1028</FONT>
1029with index <I>n</I> is the portion of the
17345e5a 1030string matching the <I>n</I>th parenthesized subexpression.
74091dd4
CR
1031Bash sets
1032<FONT SIZE=-1><B>BASH_REMATCH</B>
1033
1034</FONT>
1035in the global scope; declaring it as a local variable will lead to
1036unexpected results.
17345e5a
JA
1037<P>
1038
1039
1040Expressions may be combined using the following operators, listed
1041in decreasing order of precedence:
1042<P>
1043
1044
1045<DL COMPACT><DT><DD>
1046
1047<DL COMPACT>
1048<DT><B>( </B><I>expression</I> )
1049
1050<DD>
1051Returns the value of <I>expression</I>.
1052This may be used to override the normal precedence of operators.
1053<DT><B>! </B><I>expression</I>
1054
1055<DD>
1056True if
1057<I>expression</I>
1058
1059is false.
1060<DT><I>expression1</I> <B>&amp;&amp;</B> <I>expression2</I><DD>
1061True if both
1062<I>expression1</I>
1063
1064and
1065<I>expression2</I>
1066
1067are true.
495aee44 1068<DT><I>expression1</I> <B>||</B> <I>expression2</I><DD>
17345e5a
JA
1069True if either
1070<I>expression1</I>
1071
1072or
1073<I>expression2</I>
1074
1075is true.
1076
1077</DL>
1078<P>
1079
495aee44 1080The <B>&amp;&amp;</B> and <B>||</B>
17345e5a
JA
1081operators do not evaluate <I>expression2</I> if the value of
1082<I>expression1</I> is sufficient to determine the return value of
1083the entire conditional expression.
1084</DL>
1085
0001803f 1086<DT><B>for</B> <I>name</I> [ [ <B>in</B> [ <I>word ...</I> ] ] ; ] <B>do</B> <I>list</I> ; <B>done</B><DD>
17345e5a
JA
1087The list of words following <B>in</B> is expanded, generating a list
1088of items.
1089The variable <I>name</I> is set to each element of this list
1090in turn, and <I>list</I> is executed each time.
1091If the <B>in</B> <I>word</I> is omitted, the <B>for</B> command executes
1092<I>list</I> once for each positional parameter that is set (see
1093<FONT SIZE=-1><B>PARAMETERS</B>
1094
1095</FONT>
1096below).
1097The return status is the exit status of the last command that executes.
1098If the expansion of the items following <B>in</B> results in an empty
1099list, no commands are executed, and the return status is 0.
1100<DT><B>for</B> (( <I>expr1</I> ; <I>expr2</I> ; <I>expr3</I> )) ; <B>do</B> <I>list</I> ; <B>done</B><DD>
1101First, the arithmetic expression <I>expr1</I> is evaluated according
1102to the rules described below under
1103<FONT SIZE=-1><B>ARITHMETIC EVALUATION</B>.
1104
1105</FONT>
1106The arithmetic expression <I>expr2</I> is then evaluated repeatedly
1107until it evaluates to zero.
1108Each time <I>expr2</I> evaluates to a non-zero value, <I>list</I> is
1109executed and the arithmetic expression <I>expr3</I> is evaluated.
1110If any expression is omitted, it behaves as if it evaluates to 1.
1111The return value is the exit status of the last command in <I>list</I>
1112that is executed, or false if any of the expressions is invalid.
1113<DT><B>select</B> <I>name</I> [ <B>in</B> <I>word</I> ] ; <B>do</B> <I>list</I> ; <B>done</B><DD>
1114The list of words following <B>in</B> is expanded, generating a list
74091dd4 1115of items, and the set of expanded words is printed on the standard
17345e5a
JA
1116error, each preceded by a number. If the <B>in</B>
1117<I>word</I> is omitted, the positional parameters are printed (see
1118<FONT SIZE=-1><B>PARAMETERS</B>
1119
1120</FONT>
74091dd4
CR
1121below).
1122<B>select</B>
1123
1124then displays the
0001803f 1125<FONT SIZE=-1><B>PS3</B>
17345e5a 1126
0001803f 1127</FONT>
74091dd4 1128prompt and reads a line from the standard input.
17345e5a
JA
1129If the line consists of a number corresponding to one of
1130the displayed words, then the value of
1131<I>name</I>
1132
74091dd4
CR
1133is set to that word.
1134If the line is empty, the words and prompt are displayed again.
1135If EOF is read, the <B>select</B> command completes and returns 1.
1136Any other value read causes
17345e5a
JA
1137<I>name</I>
1138
1139to be set to null. The line read is saved in the variable
0001803f 1140<FONT SIZE=-1><B>REPLY</B>.
17345e5a 1141
0001803f 1142</FONT>
17345e5a
JA
1143The
1144<I>list</I>
1145
1146is executed after each selection until a
1147<B>break</B>
1148
1149command is executed.
1150The exit status of
1151<B>select</B>
1152
1153is the exit status of the last command executed in
1154<I>list</I>,
1155
1156or zero if no commands were executed.
1157<DT><B>case</B> <I>word</I> <B>in</B> [ [(] <I>pattern</I> [ <B>|</B> <I>pattern</I> ]
1158<DD>
1159A <B>case</B> command first expands <I>word</I>, and tries to match
d233b485
CR
1160it against each <I>pattern</I> in turn, using the matching rules
1161described under
1162<B>Pattern Matching</B>
17345e5a 1163
d233b485 1164below.
17345e5a 1165The <I>word</I> is expanded using tilde
a0c0a00f 1166expansion, parameter and variable expansion, arithmetic expansion,
17345e5a
JA
1167command substitution, process substitution and quote removal.
1168Each <I>pattern</I> examined is expanded using tilde
a0c0a00f 1169expansion, parameter and variable expansion, arithmetic expansion,
74091dd4 1170command substitution, process substitution, and quote removal.
a0c0a00f 1171If the
17345e5a
JA
1172<B>nocasematch</B>
1173
a0c0a00f 1174shell option is enabled, the match is performed without regard to the case
17345e5a
JA
1175of alphabetic characters.
1176When a match is found, the corresponding <I>list</I> is executed.
1177If the <B>;;</B> operator is used, no subsequent matches are attempted after
1178the first pattern match.
1179Using <B>;&amp;</B> in place of <B>;;</B> causes execution to continue with
1180the <I>list</I> associated with the next set of patterns.
1181Using <B>;;&amp;</B> in place of <B>;;</B> causes the shell to test the next
1182pattern list in the statement, if any, and execute any associated <I>list</I>
8868edaf
CR
1183on a successful match,
1184continuing the case statement execution as if the pattern list had not matched.
17345e5a
JA
1185The exit status is zero if no
1186pattern matches. Otherwise, it is the exit status of the
1187last command executed in <I>list</I>.
ac50fbac 1188<DT><B>if</B> <I>list</I>; <B>then</B> <I>list</I>; [ <B>elif</B> <I>list</I>; <B>then</B> <I>list</I>; ] ... [ <B>else</B> <I>list</I>; ] <B>fi</B><DD>
17345e5a 1189The
a0c0a00f 1190<B>if</B>
17345e5a
JA
1191
1192<I>list</I>
1193
1194is executed. If its exit status is zero, the
1195<B>then</B> <I>list</I> is executed. Otherwise, each <B>elif</B>
1196<I>list</I> is executed in turn, and if its exit status is zero,
1197the corresponding <B>then</B> <I>list</I> is executed and the
1198command completes. Otherwise, the <B>else</B> <I>list</I> is
1199executed, if present. The exit status is the exit status of the
1200last command executed, or zero if no condition tested true.
495aee44 1201<DT><B>while</B> <I>list-1</I>; <B>do</B> <I>list-2</I>; <B>done</B><DD>
17345e5a 1202
495aee44 1203<DT><B>until</B> <I>list-1</I>; <B>do</B> <I>list-2</I>; <B>done</B><DD>
17345e5a 1204
495aee44
CR
1205The <B>while</B> command continuously executes the list
1206<I>list-2</I> as long as the last command in the list <I>list-1</I> returns
17345e5a 1207an exit status of zero. The <B>until</B> command is identical
a0c0a00f 1208to the <B>while</B> command, except that the test is negated:
495aee44 1209<I>list-2</I>
17345e5a
JA
1210
1211is executed as long as the last command in
495aee44 1212<I>list-1</I>
17345e5a
JA
1213
1214returns a non-zero exit status.
1215The exit status of the <B>while</B> and <B>until</B> commands
1216is the exit status
495aee44 1217of the last command executed in <I>list-2</I>, or zero if
17345e5a
JA
1218none was executed.
1219</DL>
1220<A NAME="lbAP">&nbsp;</A>
1221<H4>Coprocesses</H4>
1222
17345e5a
JA
1223A <I>coprocess</I> is a shell command preceded by the <B>coproc</B> reserved
1224word.
1225A coprocess is executed asynchronously in a subshell, as if the command
1226had been terminated with the <B>&amp;</B> control operator, with a two-way pipe
1227established between the executing shell and the coprocess.
1228<P>
1229
74091dd4 1230The syntax for a coprocess is:
17345e5a
JA
1231<DL COMPACT><DT><DD>
1232<P>
1233
1234<B>coproc</B> [<I>NAME</I>] <I>command</I> [<I>redirections</I>]
1235</DL>
1236
1237<P>
1238
1239This creates a coprocess named <I>NAME</I>.
74091dd4
CR
1240<I>command</I> may be either a simple command or a compound
1241command (see above).
1242<I>NAME</I> is a shell variable name.
ac50fbac 1243If <I>NAME</I> is not supplied, the default name is <B>COPROC</B>.
74091dd4
CR
1244<P>
1245
1246The recommended form to use for a coprocess is
1247<DL COMPACT><DT><DD>
1248<P>
1249
1250<B>coproc</B> <I>NAME</I> { <I>command</I> [<I>redirections</I>]; }
1251</DL>
1252
1253<P>
1254
1255This form is recommended because simple commands result in the coprocess
1256always being named <B>COPROC</B>, and it is simpler to use and more complete
1257than the other compound commands.
1258<P>
1259
1260If <I>command</I> is a compound command, <I>NAME</I> is optional. The
1261word following <B>coproc</B> determines whether that word is interpreted
1262as a variable name: it is interpreted as <I>NAME</I> if it is not a
1263reserved word that introduces a compound command.
1264If <I>command</I> is a simple command, <I>NAME</I> is not allowed; this
1265is to avoid confusion between <I>NAME</I> and the first word of the simple
1266command.
1267<P>
1268
ac50fbac 1269When the coprocess is executed, the shell creates an array variable (see
17345e5a
JA
1270<B>Arrays</B>
1271
1272below) named <I>NAME</I> in the context of the executing shell.
1273The standard output of
1274<I>command</I>
1275
1276is connected via a pipe to a file descriptor in the executing shell,
1277and that file descriptor is assigned to <I>NAME</I>[0].
1278The standard input of
1279<I>command</I>
1280
1281is connected via a pipe to a file descriptor in the executing shell,
1282and that file descriptor is assigned to <I>NAME</I>[1].
1283This pipe is established before any redirections specified by the
1284command (see
1285<FONT SIZE=-1><B>REDIRECTION</B>
1286
1287</FONT>
1288below).
1289The file descriptors can be utilized as arguments to shell commands
1290and redirections using standard word expansions.
d233b485
CR
1291Other than those created to execute command and process substitutions,
1292the file descriptors are not available in subshells.
74091dd4
CR
1293<P>
1294
495aee44 1295The process ID of the shell spawned to execute the coprocess is
17345e5a
JA
1296available as the value of the variable <I>NAME</I>_PID.
1297The <B>wait</B>
1298builtin command may be used to wait for the coprocess to terminate.
1299<P>
1300
ac50fbac
CR
1301Since the coprocess is created as an asynchronous command,
1302the <B>coproc</B> command always returns success.
17345e5a
JA
1303The return status of a coprocess is the exit status of <I>command</I>.
1304<A NAME="lbAQ">&nbsp;</A>
1305<H4>Shell Function Definitions</H4>
1306
17345e5a
JA
1307A shell function is an object that is called like a simple command and
1308executes a compound command with a new set of positional parameters.
1309Shell functions are declared as follows:
1310<DL COMPACT>
8868edaf 1311<DT><I>fname</I> () <I>compound-command</I> [<I>redirection</I>]<DD>
495aee44 1312
8868edaf 1313<DT><B>function</B> <I>fname</I> [()] <I>compound-command</I> [<I>redirection</I>]<DD>
495aee44 1314
8868edaf 1315This defines a function named <I>fname</I>.
17345e5a
JA
1316The reserved word <B>function</B> is optional.
1317If the <B>function</B> reserved word is supplied, the parentheses are optional.
1318The <I>body</I> of the function is the compound command
a0c0a00f 1319<I>compound-command</I>
17345e5a
JA
1320
1321(see <B>Compound Commands</B> above).
1322That command is usually a <I>list</I> of commands between { and }, but
74091dd4
CR
1323may be any command listed under <B>Compound Commands</B> above.
1324If the <B>function</B> reserved word is used, but the
1325parentheses are not supplied, the braces are recommended.
8868edaf 1326<I>compound-command</I> is executed whenever <I>fname</I> is specified as the
17345e5a 1327name of a simple command.
8868edaf
CR
1328When in <I>posix mode</I>, <I>fname</I> must be a valid shell <I>name</I>
1329and may not be the name of one of the
ac50fbac 1330POSIX <I>special builtins</I>.
8868edaf
CR
1331In default mode, a function name can be any unquoted shell word that does
1332not contain <B>$</B>.
17345e5a
JA
1333Any redirections (see
1334<FONT SIZE=-1><B>REDIRECTION</B>
1335
1336</FONT>
1337below) specified when a function is defined are performed
1338when the function is executed.
1339The exit status of a function definition is zero unless a syntax error
1340occurs or a readonly function with the same name already exists.
1341When executed, the exit status of a function is the exit status of the
1342last command executed in the body. (See
1343<FONT SIZE=-1><B>FUNCTIONS</B>
1344
1345</FONT>
1346below.)
1347</DL>
1348<A NAME="lbAR">&nbsp;</A>
1349<H3>COMMENTS</H3>
1350
1351In a non-interactive shell, or an interactive shell in which the
1352<B>interactive_comments</B>
1353
1354option to the
1355<B>shopt</B>
1356
1357builtin is enabled (see
1358<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
1359
1360</FONT>
1361below), a word beginning with
1362<B>#</B>
1363
1364causes that word and all remaining characters on that line to
1365be ignored. An interactive shell without the
1366<B>interactive_comments</B>
1367
1368option enabled does not allow comments. The
1369<B>interactive_comments</B>
1370
1371option is on by default in interactive shells.
1372<A NAME="lbAS">&nbsp;</A>
1373<H3>QUOTING</H3>
1374
1375<I>Quoting</I> is used to remove the special meaning of certain
a0c0a00f 1376characters or words to the shell. Quoting can be used to
17345e5a
JA
1377disable special treatment for special characters, to prevent
1378reserved words from being recognized as such, and to prevent
1379parameter expansion.
1380<P>
1381
1382Each of the <I>metacharacters</I> listed above under
1383<FONT SIZE=-1><B>DEFINITIONS</B>
1384
1385</FONT>
1386has special meaning to the shell and must be quoted if it is to
1387represent itself.
1388<P>
1389
1390When the command history expansion facilities are being used
1391(see
1392<FONT SIZE=-1><B>HISTORY EXPANSION</B>
1393
1394</FONT>
1395below), the
1396<I>history expansion</I> character, usually <B>!</B>, must be quoted
1397to prevent history expansion.
1398<P>
1399
1400There are three quoting mechanisms: the
1401<I>escape character</I>,
1402
1403single quotes, and double quotes.
1404<P>
1405
1406A non-quoted backslash (<B>\</B>) is the
1407<I>escape character</I>.
1408
1409It preserves the literal value of the next character that follows,
1410with the exception of &lt;newline&gt;. If a <B>\</B>&lt;newline&gt; pair
1411appears, and the backslash is not itself quoted, the <B>\</B>&lt;newline&gt;
1412is treated as a line continuation (that is, it is removed from the
1413input stream and effectively ignored).
1414<P>
1415
1416Enclosing characters in single quotes preserves the literal value
1417of each character within the quotes. A single quote may not occur
1418between single quotes, even when preceded by a backslash.
1419<P>
1420
1421Enclosing characters in double quotes preserves the literal value
1422of all characters within the quotes, with the exception of
1423<B>$</B>,
1424
1425<B>`</B>,
1426
1427<B>\</B>,
1428
1429and, when history expansion is enabled,
1430<B>!</B>.
1431
a0c0a00f
CR
1432When the shell is in <I>posix mode</I>, the <B>!</B> has no special meaning
1433within double quotes, even when history expansion is enabled.
17345e5a
JA
1434The characters
1435<B>$</B>
1436
1437and
1438<B>`</B>
1439
1440retain their special meaning within double quotes. The backslash
1441retains its special meaning only when followed by one of the following
1442characters:
1443<B>$</B>,
1444
1445<B>`</B>,
1446
1447<B>&quot;</B>,
1448<B>\</B>,
1449
1450or
1451<B>&lt;newline&gt;</B>.
1452
1453A double quote may be quoted within double quotes by preceding it with
1454a backslash.
1455If enabled, history expansion will be performed unless an
1456<B>!</B>
1457
1458appearing in double quotes is escaped using a backslash.
1459The backslash preceding the
1460<B>!</B>
1461
1462is not removed.
1463<P>
1464
1465The special parameters
1466<B>*</B>
1467
1468and
1469<B>@</B>
1470
1471have special meaning when in double
1472quotes (see
1473<FONT SIZE=-1><B>PARAMETERS</B>
1474
1475</FONT>
1476below).
1477<P>
1478
74091dd4
CR
1479Character sequences of the form <B>$</B>aq<I>string</I>aq are treated
1480as a special variant of single quotes.
1481The sequence expands to <I>string</I>, with backslash-escaped characters
1482in <I>string</I> replaced as specified by the ANSI C standard.
1483Backslash escape sequences, if present, are decoded as follows:
17345e5a
JA
1484<DL COMPACT><DT><DD>
1485
1486<DL COMPACT>
1487<DT><B>\a</B>
1488
1489<DD>
1490alert (bell)
1491<DT><B>\b</B>
1492
1493<DD>
1494backspace
1495<DT><B>\e</B>
1496
0001803f
CR
1497<DD>
1498<DT><B>\E</B>
1499
17345e5a
JA
1500<DD>
1501an escape character
1502<DT><B>\f</B>
1503
1504<DD>
1505form feed
1506<DT><B>\n</B>
1507
1508<DD>
1509new line
1510<DT><B>\r</B>
1511
1512<DD>
1513carriage return
1514<DT><B>\t</B>
1515
1516<DD>
1517horizontal tab
1518<DT><B>\v</B>
1519
1520<DD>
1521vertical tab
1522<DT><B>\\</B>
1523
1524<DD>
1525backslash
1526<DT><B>\aq</B>
1527
1528<DD>
1529single quote
0001803f
CR
1530<DT><B>\dq</B>
1531
1532<DD>
1533double quote
a0c0a00f
CR
1534<DT><B>\?</B>
1535
1536<DD>
1537question mark
17345e5a
JA
1538<DT><B>\</B><I>nnn</I>
1539
1540<DD>
1541the eight-bit character whose value is the octal value <I>nnn</I>
d233b485 1542(one to three octal digits)
17345e5a
JA
1543<DT><B>\x</B><I>HH</I>
1544
1545<DD>
1546the eight-bit character whose value is the hexadecimal value <I>HH</I>
1547(one or two hex digits)
495aee44
CR
1548<DT><B>\u</B><I>HHHH</I>
1549
1550<DD>
1551the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
1552<I>HHHH</I> (one to four hex digits)
1553<DT><B>\U</B><I>HHHHHHHH</I>
1554
1555<DD>
1556the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
1557<I>HHHHHHHH</I> (one to eight hex digits)
17345e5a
JA
1558<DT><B>\c</B><I>x</I>
1559
1560<DD>
1561a control-<I>x</I> character
1562
1563</DL></DL>
1564
1565<P>
1566
1567The expanded result is single-quoted, as if the dollar sign had
1568not been present.
1569<P>
1570
0001803f
CR
1571A double-quoted string preceded by a dollar sign (<B>$</B>dq<I>string</I>dq)
1572will cause the string to be translated according to the current locale.
74091dd4
CR
1573The <I>gettext</I> infrastructure performs the lookup and
1574translation, using the <B>LC_MESSAGES</B>, <B>TEXTDOMAINDIR</B>,
1575and <B>TEXTDOMAIN</B> shell variables.
8868edaf 1576If the current locale is <B>C</B> or <B>POSIX</B>,
74091dd4
CR
1577if there are no translations available,
1578or if the string is not translated,
8868edaf 1579the dollar sign is ignored.
74091dd4
CR
1580This is a form of double quoting, so the string remains double-quoted
1581by default, whether or not it is translated and replaced.
1582If the <B>noexpand_translation</B> option is enabled
1583using the <B>shopt</B> builtin,
1584translated strings are single-quoted instead of double-quoted.
1585See the description of
1586<B>shopt</B>
1587
1588below under
1589<FONT SIZE=-1><B>SHELL</B>BUILTIN<B>COMMANDS</B>.
1590
1591</FONT>
17345e5a
JA
1592<A NAME="lbAT">&nbsp;</A>
1593<H3>PARAMETERS</H3>
1594
1595A
1596<I>parameter</I>
1597
1598is an entity that stores values.
1599It can be a
1600<I>name</I>,
1601
1602a number, or one of the special characters listed below under
1603<B>Special Parameters</B>.
1604
1605A
1606<I>variable</I>
1607
1608is a parameter denoted by a
1609<I>name</I>.
1610
1611A variable has a <I>value</I> and zero or more <I>attributes</I>.
1612Attributes are assigned using the
1613<B>declare</B>
1614
1615builtin command (see
1616<B>declare</B>
1617
1618below in
1619<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>).
1620
1621</FONT>
1622<P>
1623
1624A parameter is set if it has been assigned a value. The null string is
1625a valid value. Once a variable is set, it may be unset only by using
1626the
1627<B>unset</B>
1628
1629builtin command (see
1630<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
1631
1632</FONT>
1633below).
1634<P>
1635
1636A
1637<I>variable</I>
1638
1639may be assigned to by a statement of the form
1640<DL COMPACT><DT><DD>
1641<P>
1642
1643<I>name</I>=[<I>value</I>]
1644</DL>
1645
1646<P>
1647
1648If
1649<I>value</I>
1650
1651is not given, the variable is assigned the null string. All
1652<I>values</I>
1653
1654undergo tilde expansion, parameter and variable expansion,
1655command substitution, arithmetic expansion, and quote
1656removal (see
1657<FONT SIZE=-1><B>EXPANSION</B>
1658
1659</FONT>
1660below). If the variable has its
1661<B>integer</B>
1662
1663attribute set, then
1664<I>value</I>
1665
1666is evaluated as an arithmetic expression even if the $((...)) expansion is
1667not used (see
1668<B>Arithmetic Expansion</B>
1669
1670below).
74091dd4 1671Word splitting and pathname expansion are not performed.
17345e5a
JA
1672Assignment statements may also appear as arguments to the
1673<B>alias</B>,
1674
1675<B>declare</B>,
1676
1677<B>typeset</B>,
1678
1679<B>export</B>,
1680
1681<B>readonly</B>,
1682
1683and
1684<B>local</B>
1685
a0c0a00f 1686builtin commands (<I>declaration</I> commands).
ac50fbac
CR
1687When in <I>posix mode</I>, these builtins may appear in a command after
1688one or more instances of the <B>command</B> builtin and retain these
1689assignment statement properties.
17345e5a
JA
1690<P>
1691
1692In the context where an assignment statement is assigning a value
1693to a shell variable or array index, the += operator can be used to
1694append to or add to the variable's previous value.
a0c0a00f
CR
1695This includes arguments to builtin commands such as <B>declare</B> that
1696accept assignment statements (<I>declaration</I> commands).
74091dd4 1697When += is applied to a variable for which the <B>integer</B> attribute has been
17345e5a
JA
1698set, <I>value</I> is evaluated as an arithmetic expression and added to the
1699variable's current value, which is also evaluated.
1700When += is applied to an array variable using compound assignment (see
1701<B>Arrays</B>
1702
1703below), the
1704variable's value is not unset (as it is when using =), and new values are
1705appended to the array beginning at one greater than the array's maximum index
1706(for indexed arrays) or added as additional key-value pairs in an
1707associative array.
1708When applied to a string-valued variable, <I>value</I> is expanded and
1709appended to the variable's value.
ac50fbac
CR
1710<P>
1711
1712A variable can be assigned the <I>nameref</I> attribute using the
1713<B>-n</B> option to the <B>declare</B> or <B>local</B> builtin commands
1714(see the descriptions of <B>declare</B> and <B>local</B> below)
1715to create a <I>nameref</I>, or a reference to another variable.
1716This allows variables to be manipulated indirectly.
a0c0a00f
CR
1717Whenever the nameref variable is referenced, assigned to, unset, or has
1718its attributes modified (other than using or changing the <I>nameref</I>
1719attribute itself), the
1720operation is actually performed on the variable specified by the nameref
1721variable's value.
ac50fbac
CR
1722A nameref is commonly used within shell functions to refer to a variable
1723whose name is passed as an argument to the function.
1724For instance, if a variable name is passed to a shell function as its first
1725argument, running
1726<P>
1727<DL COMPACT><DT><DD>
1728<TT>declare -n ref=$1</TT>
1729
1730</DL>
1731
1732<P>
1733inside the function creates a nameref variable <B>ref</B> whose value is
1734the variable name passed as the first argument.
a0c0a00f
CR
1735References and assignments to <B>ref</B>, and changes to its attributes,
1736are treated as references, assignments, and attribute modifications
1737to the variable whose name was passed as <B>$1</B>.
ac50fbac
CR
1738If the control variable in a <B>for</B> loop has the nameref attribute,
1739the list of words can be a list of shell variables, and a name reference
1740will be established for each word in the list, in turn, when the loop is
1741executed.
a0c0a00f 1742Array variables cannot be given the <B>nameref</B> attribute.
ac50fbac
CR
1743However, nameref variables can reference array variables and subscripted
1744array variables.
1745Namerefs can be unset using the <B>-n</B> option to the <B>unset</B> builtin.
1746Otherwise, if <B>unset</B> is executed with the name of a nameref variable
1747as an argument, the variable referenced by the nameref variable will be unset.
17345e5a
JA
1748<A NAME="lbAU">&nbsp;</A>
1749<H4>Positional Parameters</H4>
1750
17345e5a
JA
1751A
1752<I>positional parameter</I>
1753
1754is a parameter denoted by one or more
1755digits, other than the single digit 0. Positional parameters are
1756assigned from the shell's arguments when it is invoked,
1757and may be reassigned using the
1758<B>set</B>
1759
1760builtin command. Positional parameters may not be assigned to
1761with assignment statements. The positional parameters are
1762temporarily replaced when a shell function is executed (see
1763<FONT SIZE=-1><B>FUNCTIONS</B>
1764
1765</FONT>
1766below).
1767<P>
1768
1769When a positional parameter consisting of more than a single
1770digit is expanded, it must be enclosed in braces (see
1771<FONT SIZE=-1><B>EXPANSION</B>
1772
1773</FONT>
1774below).
1775<A NAME="lbAV">&nbsp;</A>
1776<H4>Special Parameters</H4>
1777
17345e5a
JA
1778The shell treats several parameters specially. These parameters may
1779only be referenced; assignment to them is not allowed.
1780
1781<DL COMPACT>
1782<DT><B>*</B>
1783
1784<DD>
ac50fbac
CR
1785Expands to the positional parameters, starting from one.
1786When the expansion is not within double quotes, each positional parameter
1787expands to a separate word.
1788In contexts where it is performed, those words
1789are subject to further word splitting and pathname expansion.
1790When the expansion occurs within double quotes, it expands to a single word
a0c0a00f 1791with the value of each parameter separated by the first character of the
17345e5a
JA
1792<FONT SIZE=-1><B>IFS</B>
1793
1794</FONT>
1795special variable. That is, &quot;<B>$*</B>&quot; is equivalent
1796to &quot;<B>$1</B><I>c</I><B>$2</B><I>c</I><B>...</B>&quot;, where
1797<I>c</I>
1798
1799is the first character of the value of the
1800<FONT SIZE=-1><B>IFS</B>
1801
1802</FONT>
1803variable. If
1804<FONT SIZE=-1><B>IFS</B>
1805
1806</FONT>
1807is unset, the parameters are separated by spaces.
1808If
1809<FONT SIZE=-1><B>IFS</B>
1810
1811</FONT>
1812is null, the parameters are joined without intervening separators.
1813<DT><B>@</B>
1814
1815<DD>
d233b485
CR
1816Expands to the positional parameters, starting from one.
1817In contexts where word splitting is performed, this expands each
1818positional parameter to a separate word; if not within double
1819quotes, these words are subject to word splitting.
1820In contexts where word splitting is not performed,
1821this expands to a single word
1822with each positional parameter separated by a space.
1823When the
17345e5a
JA
1824expansion occurs within double quotes, each parameter expands to a
1825separate word. That is, &quot;<B>$@</B>&quot; is equivalent to
1826&quot;<B>$1</B>&quot; &quot;<B>$2</B>&quot; ...
1827If the double-quoted expansion occurs within a word, the expansion of
1828the first parameter is joined with the beginning part of the original
1829word, and the expansion of the last parameter is joined with the last
1830part of the original word.
a0c0a00f 1831When there are no positional parameters, &quot;<B>$@</B>&quot; and
17345e5a
JA
1832<B>$@</B>
1833
1834expand to nothing (i.e., they are removed).
1835<DT><B>#</B>
1836
1837<DD>
1838Expands to the number of positional parameters in decimal.
1839<DT><B>?</B>
1840
1841<DD>
1842Expands to the exit status of the most recently executed foreground
1843pipeline.
1844<DT><B>-</B>
1845
1846<DD>
8868edaf 1847Expands to the current option flags as specified upon invocation,
17345e5a
JA
1848by the
1849<B>set</B>
1850
1851builtin command, or those set by the shell itself
1852(such as the
1853<B>-i</B>
1854
1855option).
1856<DT><B>$</B>
1857
1858<DD>
74091dd4 1859Expands to the process ID of the shell. In a subshell, it
17345e5a
JA
1860expands to the process ID of the current shell, not the
1861subshell.
1862<DT><B>!</B>
1863
1864<DD>
ac50fbac
CR
1865Expands to the process ID of the job most recently placed into the
1866background, whether executed as an asynchronous command or using
1867the <B>bg</B> builtin (see
1868<FONT SIZE=-1><B>JOB CONTROL</B>
1869
1870</FONT>
1871below).
17345e5a
JA
1872<DT><B>0</B>
1873
1874<DD>
1875Expands to the name of the shell or shell script. This is set at
1876shell initialization. If
1877<B>bash</B>
1878
1879is invoked with a file of commands,
1880<B>$0</B>
1881
1882is set to the name of that file. If
1883<B>bash</B>
1884
1885is started with the
1886<B>-c</B>
1887
1888option, then
1889<B>$0</B>
1890
1891is set to the first argument after the string to be
1892executed, if one is present. Otherwise, it is set
ac50fbac 1893to the filename used to invoke
17345e5a
JA
1894<B>bash</B>,
1895
1896as given by argument zero.
8868edaf
CR
1897
1898</DL>
1899<A NAME="lbAW">&nbsp;</A>
1900<H4>Shell Variables</H4>
1901
1902The following variables are set by the shell:
1903<P>
1904
1905
1906<DL COMPACT>
17345e5a
JA
1907<DT><B>_</B>
1908
1909<DD>
8868edaf 1910At shell startup, set to the pathname used to invoke the
17345e5a
JA
1911shell or shell script being executed as passed in the environment
1912or argument list.
d233b485
CR
1913Subsequently, expands to the last argument to the previous simple
1914command executed in the foreground, after expansion.
17345e5a
JA
1915Also set to the full pathname used to invoke each command executed
1916and placed in the environment exported to that command.
1917When checking mail, this parameter holds the name of the mail file
1918currently being checked.
17345e5a
JA
1919<DT><B>BASH</B>
1920
1921<DD>
ac50fbac 1922Expands to the full filename used to invoke this instance of
17345e5a
JA
1923<B>bash</B>.
1924
0001803f
CR
1925<DT><B>BASHOPTS</B>
1926
1927<DD>
1928A colon-separated list of enabled shell options. Each word in
1929the list is a valid argument for the
1930<B>-s</B>
1931
1932option to the
1933<B>shopt</B>
1934
1935builtin command (see
1936<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
1937
1938</FONT>
1939below). The options appearing in
1940<FONT SIZE=-1><B>BASHOPTS</B>
1941
1942</FONT>
1943are those reported as
1944<I>on</I>
1945
1946by <B>shopt</B>.
1947If this variable is in the environment when
1948<B>bash</B>
1949
1950starts up, each shell option in the list will be enabled before
1951reading any startup files.
1952This variable is read-only.
17345e5a
JA
1953<DT><B>BASHPID</B>
1954
1955<DD>
495aee44 1956Expands to the process ID of the current <B>bash</B> process.
17345e5a
JA
1957This differs from <B>$$</B> under certain circumstances, such as subshells
1958that do not require <B>bash</B> to be re-initialized.
d233b485
CR
1959Assignments to
1960<FONT SIZE=-1><B>BASHPID</B>
1961
1962</FONT>
1963have no effect.
1964If
1965<B>BASHPID</B>
1966
1967is unset, it loses its special properties, even if it is
1968subsequently reset.
17345e5a
JA
1969<DT><B>BASH_ALIASES</B>
1970
1971<DD>
1972An associative array variable whose members correspond to the internal
495aee44 1973list of aliases as maintained by the <B>alias</B> builtin.
a0c0a00f
CR
1974Elements added to this array appear in the alias list; however,
1975unsetting array elements currently does not cause aliases to be removed
1976from the alias list.
1977If
1978<B>BASH_ALIASES</B>
1979
1980is unset, it loses its special properties, even if it is
1981subsequently reset.
17345e5a
JA
1982<DT><B>BASH_ARGC</B>
1983
1984<DD>
1985An array variable whose values are the number of parameters in each
1986frame of the current <B>bash</B> execution call stack.
1987The number of
1988parameters to the current subroutine (shell function or script executed
1989with <B>.</B> or <B>source</B>) is at the top of the stack.
1990When a subroutine is executed, the number of parameters passed is pushed onto
0001803f
CR
1991<FONT SIZE=-1><B>BASH_ARGC</B>.
1992
1993</FONT>
1994The shell sets
1995<FONT SIZE=-1><B>BASH_ARGC</B>
1996
1997</FONT>
1998only when in extended debugging mode (see the description of the
17345e5a
JA
1999<B>extdebug</B>
2000
2001option to the
2002<B>shopt</B>
2003
d233b485
CR
2004builtin below).
2005Setting <B>extdebug</B> after the shell has started to execute a script,
2006or referencing this variable when <B>extdebug</B> is not set,
2007may result in inconsistent values.
17345e5a
JA
2008<DT><B>BASH_ARGV</B>
2009
2010<DD>
2011An array variable containing all of the parameters in the current <B>bash</B>
2012execution call stack. The final parameter of the last subroutine call
2013is at the top of the stack; the first parameter of the initial call is
2014at the bottom. When a subroutine is executed, the parameters supplied
0001803f
CR
2015are pushed onto
2016<FONT SIZE=-1><B>BASH_ARGV</B>.
2017
2018</FONT>
2019The shell sets
2020<FONT SIZE=-1><B>BASH_ARGV</B>
2021
2022</FONT>
2023only when in extended debugging mode
17345e5a
JA
2024(see the description of the
2025<B>extdebug</B>
2026
2027option to the
2028<B>shopt</B>
2029
d233b485
CR
2030builtin below).
2031Setting <B>extdebug</B> after the shell has started to execute a script,
2032or referencing this variable when <B>extdebug</B> is not set,
2033may result in inconsistent values.
2034<DT><B>BASH_ARGV0</B>
2035
2036<DD>
2037When referenced, this variable expands to the name of the shell or shell
2038script (identical to
2039<B>$0</B>;
2040
2041see the description of special parameter 0 above).
2042Assignment to
2043<B>BASH_ARGV0</B>
2044
2045causes the value assigned to also be assigned to <B>$0</B>.
2046If
2047<B>BASH_ARGV0</B>
2048
2049is unset, it loses its special properties, even if it is
2050subsequently reset.
17345e5a
JA
2051<DT><B>BASH_CMDS</B>
2052
2053<DD>
2054An associative array variable whose members correspond to the internal
2055hash table of commands as maintained by the <B>hash</B> builtin.
a0c0a00f
CR
2056Elements added to this array appear in the hash table; however,
2057unsetting array elements currently does not cause command names to be removed
2058from the hash table.
2059If
2060<B>BASH_CMDS</B>
2061
2062is unset, it loses its special properties, even if it is
2063subsequently reset.
17345e5a
JA
2064<DT><B>BASH_COMMAND</B>
2065
2066<DD>
2067The command currently being executed or about to be executed, unless the
2068shell is executing a command as the result of a trap,
2069in which case it is the command executing at the time of the trap.
8868edaf
CR
2070If
2071<B>BASH_COMMAND</B>
2072
2073is unset, it loses its special properties, even if it is
2074subsequently reset.
17345e5a
JA
2075<DT><B>BASH_EXECUTION_STRING</B>
2076
2077<DD>
2078The command argument to the <B>-c</B> invocation option.
2079<DT><B>BASH_LINENO</B>
2080
2081<DD>
2082An array variable whose members are the line numbers in source files
495aee44
CR
2083where each corresponding member of
2084<FONT SIZE=-1><B>FUNCNAME</B>
0001803f
CR
2085
2086</FONT>
495aee44 2087was invoked.
17345e5a 2088<B>${BASH_LINENO[</B><I>$i</I><B>]}</B> is the line number in the source
495aee44
CR
2089file (<B>${BASH_SOURCE[</B><I>$i+1</I><B>]}</B>) where
2090<B>${FUNCNAME[</B><I>$i</I><B>]}</B> was called
17345e5a
JA
2091(or <B>${BASH_LINENO[</B><I>$i-1</I><B>]}</B> if referenced within another
2092shell function).
0001803f
CR
2093Use
2094<FONT SIZE=-1><B>LINENO</B>
2095
2096</FONT>
2097to obtain the current line number.
a0c0a00f
CR
2098<DT><B>BASH_LOADABLES_PATH</B>
2099
2100<DD>
2101A colon-separated list of directories in which the shell looks for
2102dynamically loadable builtins specified by the
2103<B>enable</B>
2104
2105command.
17345e5a
JA
2106<DT><B>BASH_REMATCH</B>
2107
2108<DD>
2109An array variable whose members are assigned by the <B>=~</B> binary
2110operator to the <B>[[</B> conditional command.
2111The element with index 0 is the portion of the string
2112matching the entire regular expression.
2113The element with index <I>n</I> is the portion of the
2114string matching the <I>n</I>th parenthesized subexpression.
17345e5a
JA
2115<DT><B>BASH_SOURCE</B>
2116
2117<DD>
495aee44
CR
2118An array variable whose members are the source filenames
2119where the corresponding shell function names in the
0001803f
CR
2120<FONT SIZE=-1><B>FUNCNAME</B>
2121
2122</FONT>
495aee44
CR
2123array variable are defined.
2124The shell function
2125<B>${FUNCNAME[</B><I>$i</I><B>]}</B> is defined in the file
2126<B>${BASH_SOURCE[</B><I>$i</I><B>]}</B> and called from
2127<B>${BASH_SOURCE[</B><I>$i+1</I><B>]}</B>.
17345e5a
JA
2128<DT><B>BASH_SUBSHELL</B>
2129
2130<DD>
ac50fbac
CR
2131Incremented by one within each subshell or subshell environment when
2132the shell begins executing in that environment.
17345e5a 2133The initial value is 0.
8868edaf
CR
2134If
2135<B>BASH_SUBSHELL</B>
2136
2137is unset, it loses its special properties, even if it is
2138subsequently reset.
17345e5a
JA
2139<DT><B>BASH_VERSINFO</B>
2140
2141<DD>
2142A readonly array variable whose members hold version information for
2143this instance of
2144<B>bash</B>.
2145
2146The values assigned to the array members are as follows:
2147<P>
2148<DL COMPACT><DT><DD>
17345e5a
JA
2149<DL COMPACT>
2150<DT><B>BASH_VERSINFO[</B>0]
2151
2152<DD>
2153The major version number (the <I>release</I>).
2154<DT><B>BASH_VERSINFO[</B>1]
2155
2156<DD>
2157The minor version number (the <I>version</I>).
2158<DT><B>BASH_VERSINFO[</B>2]
2159
2160<DD>
2161The patch level.
2162<DT><B>BASH_VERSINFO[</B>3]
2163
2164<DD>
2165The build version.
2166<DT><B>BASH_VERSINFO[</B>4]
2167
2168<DD>
2169The release status (e.g., <I>beta1</I>).
2170<DT><B>BASH_VERSINFO[</B>5]
2171
2172<DD>
0001803f
CR
2173The value of
2174<FONT SIZE=-1><B>MACHTYPE</B>.
2175
2176</FONT>
17345e5a
JA
2177</DL></DL>
2178
2179<DT><B>BASH_VERSION</B>
2180
2181<DD>
2182Expands to a string describing the version of this instance of
2183<B>bash</B>.
2184
2185<DT><B>COMP_CWORD</B>
2186
2187<DD>
2188An index into <B>${COMP_WORDS}</B> of the word containing the current
2189cursor position.
2190This variable is available only in shell functions invoked by the
2191programmable completion facilities (see <B>Programmable Completion</B>
2192below).
2193<DT><B>COMP_KEY</B>
2194
2195<DD>
2196The key (or final key of a key sequence) used to invoke the current
2197completion function.
2198<DT><B>COMP_LINE</B>
2199
2200<DD>
2201The current command line.
2202This variable is available only in shell functions and external
2203commands invoked by the
2204programmable completion facilities (see <B>Programmable Completion</B>
2205below).
2206<DT><B>COMP_POINT</B>
2207
2208<DD>
2209The index of the current cursor position relative to the beginning of
2210the current command.
2211If the current cursor position is at the end of the current command,
2212the value of this variable is equal to <B>${#COMP_LINE}</B>.
2213This variable is available only in shell functions and external
2214commands invoked by the
2215programmable completion facilities (see <B>Programmable Completion</B>
2216below).
2217<DT><B>COMP_TYPE</B>
2218
2219<DD>
2220Set to an integer value corresponding to the type of completion attempted
2221that caused a completion function to be called:
2222<I>TAB</I>, for normal completion,
2223<I>?</I>, for listing completions after successive tabs,
2224<I>!</I>, for listing alternatives on partial word completion,
2225<I>@</I>, to list completions if the word is not unmodified,
2226or
2227<I>%</I>, for menu completion.
2228This variable is available only in shell functions and external
2229commands invoked by the
2230programmable completion facilities (see <B>Programmable Completion</B>
2231below).
2232<DT><B>COMP_WORDBREAKS</B>
2233
2234<DD>
0001803f 2235The set of characters that the <B>readline</B> library treats as word
17345e5a
JA
2236separators when performing word completion.
2237If
2238<FONT SIZE=-1><B>COMP_WORDBREAKS</B>
2239
2240</FONT>
2241is unset, it loses its special properties, even if it is
2242subsequently reset.
2243<DT><B>COMP_WORDS</B>
2244
2245<DD>
2246An array variable (see <B>Arrays</B> below) consisting of the individual
2247words in the current command line.
0001803f
CR
2248The line is split into words as <B>readline</B> would split it, using
2249<FONT SIZE=-1><B>COMP_WORDBREAKS</B>
2250
2251</FONT>
2252as described above.
17345e5a
JA
2253This variable is available only in shell functions invoked by the
2254programmable completion facilities (see <B>Programmable Completion</B>
2255below).
495aee44
CR
2256<DT><B>COPROC</B>
2257
2258<DD>
2259An array variable (see <B>Arrays</B> below) created to hold the file descriptors
2260for output from and input to an unnamed coprocess (see <B>Coprocesses</B>
2261above).
17345e5a
JA
2262<DT><B>DIRSTACK</B>
2263
2264<DD>
2265An array variable (see
2266<B>Arrays</B>
2267
2268below) containing the current contents of the directory stack.
2269Directories appear in the stack in the order they are displayed by the
2270<B>dirs</B>
2271
2272builtin.
2273Assigning to members of this array variable may be used to modify
2274directories already in the stack, but the
2275<B>pushd</B>
2276
2277and
2278<B>popd</B>
2279
2280builtins must be used to add and remove directories.
2281Assignment to this variable will not change the current directory.
2282If
2283<FONT SIZE=-1><B>DIRSTACK</B>
2284
d233b485
CR
2285</FONT>
2286is unset, it loses its special properties, even if it is
2287subsequently reset.
2288<DT><B>EPOCHREALTIME</B>
2289
2290<DD>
2291Each time this parameter is referenced, it expands to the number of seconds
2292since the Unix Epoch (see <I>time</I>(3)) as a floating point value
2293with micro-second granularity.
2294Assignments to
2295<FONT SIZE=-1><B>EPOCHREALTIME</B>
2296
2297</FONT>
2298are ignored.
2299If
2300<FONT SIZE=-1><B>EPOCHREALTIME</B>
2301
2302</FONT>
2303is unset, it loses its special properties, even if it is
2304subsequently reset.
2305<DT><B>EPOCHSECONDS</B>
2306
2307<DD>
2308Each time this parameter is referenced, it expands to the number of seconds
2309since the Unix Epoch (see <I>time</I>(3)).
2310Assignments to
2311<FONT SIZE=-1><B>EPOCHSECONDS</B>
2312
2313</FONT>
2314are ignored.
2315If
2316<FONT SIZE=-1><B>EPOCHSECONDS</B>
2317
17345e5a
JA
2318</FONT>
2319is unset, it loses its special properties, even if it is
2320subsequently reset.
2321<DT><B>EUID</B>
2322
2323<DD>
2324Expands to the effective user ID of the current user, initialized at
2325shell startup. This variable is readonly.
2326<DT><B>FUNCNAME</B>
2327
2328<DD>
2329An array variable containing the names of all shell functions
2330currently in the execution call stack.
2331The element with index 0 is the name of any currently-executing
2332shell function.
495aee44 2333The bottom-most element (the one with the highest index) is
17345e5a
JA
2334<TT>&quot;main&quot;</TT>.
2335
2336This variable exists only when a shell function is executing.
2337Assignments to
2338<FONT SIZE=-1><B>FUNCNAME</B>
2339
2340</FONT>
a0c0a00f 2341have no effect.
17345e5a
JA
2342If
2343<FONT SIZE=-1><B>FUNCNAME</B>
2344
2345</FONT>
2346is unset, it loses its special properties, even if it is
2347subsequently reset.
495aee44
CR
2348<P>
2349
2350
2351This variable can be used with <B>BASH_LINENO</B> and <B>BASH_SOURCE</B>.
2352Each element of <B>FUNCNAME</B> has corresponding elements in
2353<B>BASH_LINENO</B> and <B>BASH_SOURCE</B> to describe the call stack.
2354For instance, <B>${FUNCNAME[</B><I>$i</I><B>]}</B> was called from the file
2355<B>${BASH_SOURCE[</B><I>$i+1</I><B>]}</B> at line number
2356<B>${BASH_LINENO[</B><I>$i</I><B>]}</B>.
2357The <B>caller</B> builtin displays the current call stack using this
2358information.
17345e5a
JA
2359<DT><B>GROUPS</B>
2360
2361<DD>
2362An array variable containing the list of groups of which the current
2363user is a member.
a0c0a00f 2364Assignments to
17345e5a
JA
2365<FONT SIZE=-1><B>GROUPS</B>
2366
2367</FONT>
a0c0a00f 2368have no effect.
17345e5a
JA
2369If
2370<FONT SIZE=-1><B>GROUPS</B>
2371
2372</FONT>
2373is unset, it loses its special properties, even if it is
2374subsequently reset.
2375<DT><B>HISTCMD</B>
2376
2377<DD>
2378The history number, or index in the history list, of the current
2379command.
8868edaf
CR
2380Assignments to
2381<FONT SIZE=-1><B>HISTCMD</B>
2382
2383</FONT>
2384are ignored.
17345e5a
JA
2385If
2386<FONT SIZE=-1><B>HISTCMD</B>
2387
2388</FONT>
2389is unset, it loses its special properties, even if it is
2390subsequently reset.
2391<DT><B>HOSTNAME</B>
2392
2393<DD>
2394Automatically set to the name of the current host.
2395<DT><B>HOSTTYPE</B>
2396
2397<DD>
2398Automatically set to a string that uniquely
2399describes the type of machine on which
2400<B>bash</B>
2401
2402is executing.
2403The default is system-dependent.
2404<DT><B>LINENO</B>
2405
2406<DD>
2407Each time this parameter is referenced, the shell substitutes
2408a decimal number representing the current sequential line number
2409(starting with 1) within a script or function. When not in a
2410script or function, the value substituted is not guaranteed to
2411be meaningful.
2412If
2413<FONT SIZE=-1><B>LINENO</B>
2414
2415</FONT>
2416is unset, it loses its special properties, even if it is
2417subsequently reset.
2418<DT><B>MACHTYPE</B>
2419
2420<DD>
2421Automatically set to a string that fully describes the system
2422type on which
2423<B>bash</B>
2424
2425is executing, in the standard GNU <I>cpu-company-system</I> format.
2426The default is system-dependent.
495aee44
CR
2427<DT><B>MAPFILE</B>
2428
2429<DD>
2430An array variable (see <B>Arrays</B> below) created to hold the text
2431read by the <B>mapfile</B> builtin when no variable name is supplied.
17345e5a
JA
2432<DT><B>OLDPWD</B>
2433
2434<DD>
2435The previous working directory as set by the
2436<B>cd</B>
2437
2438command.
2439<DT><B>OPTARG</B>
2440
2441<DD>
2442The value of the last option argument processed by the
2443<B>getopts</B>
2444
2445builtin command (see
2446<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
2447
2448</FONT>
2449below).
2450<DT><B>OPTIND</B>
2451
2452<DD>
2453The index of the next argument to be processed by the
2454<B>getopts</B>
2455
2456builtin command (see
2457<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
2458
2459</FONT>
2460below).
2461<DT><B>OSTYPE</B>
2462
2463<DD>
2464Automatically set to a string that
2465describes the operating system on which
2466<B>bash</B>
2467
2468is executing.
2469The default is system-dependent.
2470<DT><B>PIPESTATUS</B>
2471
2472<DD>
2473An array variable (see
2474<B>Arrays</B>
2475
2476below) containing a list of exit status values from the processes
2477in the most-recently-executed foreground pipeline (which may
2478contain only a single command).
2479<DT><B>PPID</B>
2480
2481<DD>
2482The process ID of the shell's parent. This variable is readonly.
2483<DT><B>PWD</B>
2484
2485<DD>
2486The current working directory as set by the
2487<B>cd</B>
2488
2489command.
2490<DT><B>RANDOM</B>
2491
2492<DD>
8868edaf
CR
2493Each time this parameter is referenced, it expands to a random integer
2494between 0 and 32767.
2495Assigning
17345e5a 2496a value to
8868edaf 2497<FONT SIZE=-1><B>RANDOM</B>
17345e5a
JA
2498
2499</FONT>
8868edaf 2500initializes (seeds) the sequence of random numbers.
17345e5a
JA
2501If
2502<FONT SIZE=-1><B>RANDOM</B>
2503
2504</FONT>
2505is unset, it loses its special properties, even if it is
2506subsequently reset.
74091dd4
CR
2507<DT><B>READLINE_ARGUMENT</B>
2508
2509<DD>
2510Any numeric argument given to a readline command that was defined using
2511<TT>bind -x</TT>
2512
2513(see
2514<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
2515
2516</FONT>
2517below)
2518when it was invoked.
495aee44
CR
2519<DT><B>READLINE_LINE</B>
2520
2521<DD>
2522The contents of the
2523<B>readline</B>
2524
2525line buffer, for use with
2526<TT>bind -x</TT>
2527
2528(see
2529<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
2530
2531</FONT>
2532below).
8868edaf
CR
2533<DT><B>READLINE_MARK</B>
2534
2535<DD>
2536The position of the mark (saved insertion point) in the
2537<B>readline</B>
2538
2539line buffer, for use with
2540<TT>bind -x</TT>
2541
2542(see
2543<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
2544
2545</FONT>
2546below).
2547The characters between the insertion point and the mark are often
2548called the <I>region</I>.
495aee44
CR
2549<DT><B>READLINE_POINT</B>
2550
2551<DD>
2552The position of the insertion point in the
2553<B>readline</B>
2554
2555line buffer, for use with
2556<TT>bind -x</TT>
2557
2558(see
2559<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
2560
2561</FONT>
2562below).
17345e5a
JA
2563<DT><B>REPLY</B>
2564
2565<DD>
2566Set to the line of input read by the
2567<B>read</B>
2568
2569builtin command when no arguments are supplied.
2570<DT><B>SECONDS</B>
2571
2572<DD>
2573Each time this parameter is
74091dd4
CR
2574referenced, it expands to the number of seconds since shell invocation.
2575If a value is assigned to
17345e5a
JA
2576<FONT SIZE=-1><B>SECONDS</B>,
2577
2578</FONT>
2579the value returned upon subsequent
2580references is
2581the number of seconds since the assignment plus the value assigned.
74091dd4 2582The number of seconds at shell invocation and the current time are always
8868edaf 2583determined by querying the system clock.
17345e5a
JA
2584If
2585<FONT SIZE=-1><B>SECONDS</B>
2586
2587</FONT>
2588is unset, it loses its special properties, even if it is
2589subsequently reset.
2590<DT><B>SHELLOPTS</B>
2591
2592<DD>
2593A colon-separated list of enabled shell options. Each word in
2594the list is a valid argument for the
2595<B>-o</B>
2596
2597option to the
2598<B>set</B>
2599
2600builtin command (see
2601<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
2602
2603</FONT>
2604below). The options appearing in
2605<FONT SIZE=-1><B>SHELLOPTS</B>
2606
2607</FONT>
2608are those reported as
2609<I>on</I>
2610
2611by <B>set -o</B>.
2612If this variable is in the environment when
2613<B>bash</B>
2614
2615starts up, each shell option in the list will be enabled before
2616reading any startup files.
2617This variable is read-only.
2618<DT><B>SHLVL</B>
2619
2620<DD>
2621Incremented by one each time an instance of
2622<B>bash</B>
2623
2624is started.
8868edaf
CR
2625<DT><B>SRANDOM</B>
2626
2627<DD>
2628This variable expands to a 32-bit pseudo-random number each time it is
2629referenced. The random number generator is not linear on systems that
2630support <TT>/dev/urandom</TT> or <I>arc4random</I>, so each returned number
2631has no relationship to the numbers preceding it.
2632The random number generator cannot be seeded, so assignments to this
2633variable have no effect.
2634If
2635<FONT SIZE=-1><B>SRANDOM</B>
2636
2637</FONT>
2638is unset, it loses its special properties,
2639even if it is subsequently reset.
17345e5a
JA
2640<DT><B>UID</B>
2641
2642<DD>
2643Expands to the user ID of the current user, initialized at shell startup.
2644This variable is readonly.
2645
2646</DL>
2647<P>
2648
2649The following variables are used by the shell. In some cases,
2650<B>bash</B>
2651
2652assigns a default value to a variable; these cases are noted
2653below.
2654<P>
2655
2656
2657<DL COMPACT>
ac50fbac
CR
2658<DT><B>BASH_COMPAT</B>
2659
2660<DD>
2661The value is used to set the shell's compatibility level.
8868edaf
CR
2662See
2663<FONT SIZE=-1><B>SHELL COMPATIBILITY MODE</B>
2664
2665</FONT>
2666below for a description of the various compatibility
ac50fbac
CR
2667levels and their effects.
2668The value may be a decimal number (e.g., 4.2) or an integer (e.g., 42)
2669corresponding to the desired compatibility level.
2670If <B>BASH_COMPAT</B> is unset or set to the empty string, the compatibility
2671level is set to the default for the current version.
2672If <B>BASH_COMPAT</B> is set to a value that is not one of the valid
2673compatibility levels, the shell prints an error message and sets the
2674compatibility level to the default for the current version.
8868edaf
CR
2675The valid values correspond to the compatibility levels
2676described below under
74091dd4 2677<FONT SIZE=-1><B>SHELL COMPATIBILITY MODE</B>.
8868edaf
CR
2678
2679</FONT>
2680For example, 4.2 and 42 are valid values that correspond
2681to the <B>compat42</B> <B>shopt</B> option
2682and set the compatibility level to 42.
ac50fbac 2683The current version is also a valid value.
17345e5a
JA
2684<DT><B>BASH_ENV</B>
2685
2686<DD>
2687If this parameter is set when <B>bash</B> is executing a shell script,
2688its value is interpreted as a filename containing commands to
2689initialize the shell, as in
2690<A HREF="file:~/.bashrc"><I>~/.bashrc</I></A>.
2691
2692The value of
2693<FONT SIZE=-1><B>BASH_ENV</B>
2694
2695</FONT>
2696is subjected to parameter expansion, command substitution, and arithmetic
ac50fbac 2697expansion before being interpreted as a filename.
17345e5a
JA
2698<FONT SIZE=-1><B>PATH</B>
2699
2700</FONT>
ac50fbac 2701is not used to search for the resultant filename.
0001803f
CR
2702<DT><B>BASH_XTRACEFD</B>
2703
2704<DD>
2705If set to an integer corresponding to a valid file descriptor, <B>bash</B>
2706will write the trace output generated when
2707<TT>set -x</TT>
2708
2709is enabled to that file descriptor.
2710The file descriptor is closed when
2711<FONT SIZE=-1><B>BASH_XTRACEFD</B>
2712
2713</FONT>
2714is unset or assigned a new value.
2715Unsetting
2716<FONT SIZE=-1><B>BASH_XTRACEFD</B>
2717
2718</FONT>
2719or assigning it the empty string causes the
2720trace output to be sent to the standard error.
2721Note that setting
2722<FONT SIZE=-1><B>BASH_XTRACEFD</B>
2723
2724</FONT>
2725to 2 (the standard error file
2726descriptor) and then unsetting it will result in the standard error
2727being closed.
495aee44
CR
2728<DT><B>CDPATH</B>
2729
2730<DD>
2731The search path for the
2732<B>cd</B>
2733
2734command.
2735This is a colon-separated list of directories in which the shell looks
2736for destination directories specified by the
2737<B>cd</B>
2738
2739command.
2740A sample value is
2741<TT>&quot;.:~:/usr&quot;</TT>.
2742
ac50fbac
CR
2743<DT><B>CHILD_MAX</B>
2744
2745<DD>
2746Set the number of exited child status values for the shell to remember.
2747Bash will not allow this value to be decreased below a POSIX-mandated
2748minimum, and there is a maximum value (currently 8192) that this may
2749not exceed.
2750The minimum value is system-dependent.
17345e5a
JA
2751<DT><B>COLUMNS</B>
2752
2753<DD>
495aee44 2754Used by the <B>select</B> compound command to determine the terminal width
ac50fbac
CR
2755when printing selection lists.
2756Automatically set if the
2757<B>checkwinsize</B>
2758
2759option is enabled or in an interactive shell upon receipt of a
495aee44
CR
2760<FONT SIZE=-1><B>SIGWINCH</B>.
2761
2762</FONT>
17345e5a
JA
2763<DT><B>COMPREPLY</B>
2764
2765<DD>
2766An array variable from which <B>bash</B> reads the possible completions
2767generated by a shell function invoked by the programmable completion
2768facility (see <B>Programmable Completion</B> below).
ac50fbac 2769Each array element contains one possible completion.
17345e5a
JA
2770<DT><B>EMACS</B>
2771
2772<DD>
2773If <B>bash</B> finds this variable in the environment when the shell starts
2774with value
2775<TT>t</TT>,
2776
495aee44 2777it assumes that the shell is running in an Emacs shell buffer and disables
17345e5a 2778line editing.
495aee44
CR
2779<DT><B>ENV</B>
2780
2781<DD>
8868edaf
CR
2782Expanded and executed similarly to
2783<FONT SIZE=-1><B>BASH_ENV</B>
495aee44
CR
2784
2785</FONT>
8868edaf
CR
2786(see <B>INVOCATION</B> above)
2787when an interactive shell is invoked in <I>posix mode</I>.
a0c0a00f
CR
2788<DT><B>EXECIGNORE</B>
2789
2790<DD>
2791A colon-separated list of shell patterns (see <B>Pattern Matching</B>)
2792defining the list of filenames to be ignored by command search using
2793<B>PATH</B>.
2794Files whose full pathnames match one of these patterns are not considered
2795executable files for the purposes of completion and command execution
2796via <B>PATH</B> lookup.
2797This does not affect the behavior of the <B>[</B>, <B>test</B>, and <B>[[</B>
2798commands.
2799Full pathnames in the command hash table are not subject to <B>EXECIGNORE</B>.
2800Use this variable to ignore shared library files that have the executable
2801bit set, but are not executable files.
2802The pattern matching honors the setting of the <B>extglob</B> shell
2803option.
17345e5a
JA
2804<DT><B>FCEDIT</B>
2805
2806<DD>
2807The default editor for the
2808<B>fc</B>
2809
2810builtin command.
2811<DT><B>FIGNORE</B>
2812
2813<DD>
2814A colon-separated list of suffixes to ignore when performing
2815filename completion (see
2816<FONT SIZE=-1><B>READLINE</B>
2817
2818</FONT>
2819below).
8868edaf 2820A filename whose suffix matches one of the entries in
17345e5a
JA
2821<FONT SIZE=-1><B>FIGNORE</B>
2822
2823</FONT>
2824is excluded from the list of matched filenames.
2825A sample value is
2826<TT>&quot;.o:~&quot;</TT>.
2827
495aee44
CR
2828<DT><B>FUNCNEST</B>
2829
2830<DD>
2831If set to a numeric value greater than 0, defines a maximum function
2832nesting level. Function invocations that exceed this nesting level
2833will cause the current command to abort.
17345e5a
JA
2834<DT><B>GLOBIGNORE</B>
2835
2836<DD>
d233b485 2837A colon-separated list of patterns defining the set of file names to
17345e5a 2838be ignored by pathname expansion.
d233b485 2839If a file name matched by a pathname expansion pattern also matches one
17345e5a
JA
2840of the patterns in
2841<FONT SIZE=-1><B>GLOBIGNORE</B>,
2842
2843</FONT>
2844it is removed from the list of matches.
2845<DT><B>HISTCONTROL</B>
2846
2847<DD>
2848A colon-separated list of values controlling how commands are saved on
2849the history list.
2850If the list of values includes
2851<I>ignorespace</I>,
2852
2853lines which begin with a
2854<B>space</B>
2855
2856character are not saved in the history list.
a0c0a00f 2857A value of
17345e5a
JA
2858<I>ignoredups</I>
2859
2860causes lines matching the previous history entry to not be saved.
2861A value of
2862<I>ignoreboth</I>
2863
2864is shorthand for <I>ignorespace</I> and <I>ignoredups</I>.
2865A value of
2866<I>erasedups</I>
2867
2868causes all previous lines matching the current line to be removed from
2869the history list before that line is saved.
2870Any value not in the above list is ignored.
0001803f
CR
2871If
2872<FONT SIZE=-1><B>HISTCONTROL</B>
2873
2874</FONT>
2875is unset, or does not include a valid value,
17345e5a
JA
2876all lines read by the shell parser are saved on the history list,
2877subject to the value of
0001803f 2878<FONT SIZE=-1><B>HISTIGNORE</B>.
17345e5a 2879
0001803f 2880</FONT>
17345e5a
JA
2881The second and subsequent lines of a multi-line compound command are
2882not tested, and are added to the history regardless of the value of
0001803f 2883<FONT SIZE=-1><B>HISTCONTROL</B>.
17345e5a 2884
0001803f 2885</FONT>
17345e5a
JA
2886<DT><B>HISTFILE</B>
2887
2888<DD>
2889The name of the file in which command history is saved (see
2890<FONT SIZE=-1><B>HISTORY</B>
2891
2892</FONT>
2893below). The default value is <A HREF="file:~/.bash_history"><I>~/.bash_history</I></A>. If unset, the
ac50fbac 2894command history is not saved when a shell exits.
17345e5a
JA
2895<DT><B>HISTFILESIZE</B>
2896
2897<DD>
2898The maximum number of lines contained in the history file. When this
2899variable is assigned a value, the history file is truncated, if
ac50fbac
CR
2900necessary,
2901to contain no more than that number of lines by removing the oldest entries.
2902The history file is also truncated to this size after
2903writing it when a shell exits.
2904If the value is 0, the history file is truncated to zero size.
2905Non-numeric values and numeric values less than zero inhibit truncation.
2906The shell sets the default value to the value of <B>HISTSIZE</B>
2907after reading any startup files.
17345e5a
JA
2908<DT><B>HISTIGNORE</B>
2909
2910<DD>
2911A colon-separated list of patterns used to decide which command lines
2912should be saved on the history list. Each pattern is anchored at the
2913beginning of the line and must match the complete line (no implicit
2914`<B>*</B>' is appended). Each pattern is tested against the line
2915after the checks specified by
0001803f 2916<FONT SIZE=-1><B>HISTCONTROL</B>
17345e5a 2917
0001803f 2918</FONT>
17345e5a
JA
2919are applied.
2920In addition to the normal shell pattern matching characters, `<B>&amp;</B>'
2921matches the previous history line. `<B>&amp;</B>' may be escaped using a
2922backslash; the backslash is removed before attempting a match.
2923The second and subsequent lines of a multi-line compound command are
2924not tested, and are added to the history regardless of the value of
0001803f 2925<FONT SIZE=-1><B>HISTIGNORE</B>.
17345e5a 2926
0001803f 2927</FONT>
a0c0a00f
CR
2928The pattern matching honors the setting of the <B>extglob</B> shell
2929option.
17345e5a
JA
2930<DT><B>HISTSIZE</B>
2931
2932<DD>
2933The number of commands to remember in the command history (see
2934<FONT SIZE=-1><B>HISTORY</B>
2935
2936</FONT>
ac50fbac
CR
2937below).
2938If the value is 0, commands are not saved in the history list.
2939Numeric values less than zero result in every command being saved
2940on the history list (there is no limit).
2941The shell sets the default value to 500 after reading any startup files.
17345e5a
JA
2942<DT><B>HISTTIMEFORMAT</B>
2943
2944<DD>
2945If this variable is set and not null, its value is used as a format string
2946for <I>strftime</I>(3) to print the time stamp associated with each history
2947entry displayed by the <B>history</B> builtin.
2948If this variable is set, time stamps are written to the history file so
2949they may be preserved across shell sessions.
2950This uses the history comment character to distinguish timestamps from
2951other history lines.
2952<DT><B>HOME</B>
2953
2954<DD>
2955The home directory of the current user; the default argument for the
2956<B>cd</B> builtin command.
2957The value of this variable is also used when performing tilde expansion.
2958<DT><B>HOSTFILE</B>
2959
2960<DD>
2961Contains the name of a file in the same format as
2962
2963<I>/etc/hosts</I>
2964
2965that should be read when the shell needs to complete a
2966hostname.
2967The list of possible hostname completions may be changed while the
2968shell is running;
2969the next time hostname completion is attempted after the
2970value is changed,
2971<B>bash</B>
2972
2973adds the contents of the new file to the existing list.
2974If
2975<FONT SIZE=-1><B>HOSTFILE</B>
2976
2977</FONT>
0001803f
CR
2978is set, but has no value, or does not name a readable file,
2979<B>bash</B> attempts to read
17345e5a
JA
2980
2981<I>/etc/hosts</I>
2982
2983to obtain the list of possible hostname completions.
2984When
2985<FONT SIZE=-1><B>HOSTFILE</B>
2986
2987</FONT>
2988is unset, the hostname list is cleared.
2989<DT><B>IFS</B>
2990
2991<DD>
2992The
2993<I>Internal Field Separator</I>
2994
2995that is used
2996for word splitting after expansion and to
2997split lines into words with the
2998<B>read</B>
2999
3000builtin command. The default value is
3001``&lt;space&gt;&lt;tab&gt;&lt;newline&gt;''.
3002<DT><B>IGNOREEOF</B>
3003
3004<DD>
3005Controls the
3006action of an interactive shell on receipt of an
3007<FONT SIZE=-1><B>EOF</B>
3008
3009</FONT>
3010character as the sole input. If set, the value is the number of
3011consecutive
3012<FONT SIZE=-1><B>EOF</B>
3013
3014</FONT>
3015characters which must be
3016typed as the first characters on an input line before
3017<B>bash</B>
3018
3019exits. If the variable exists but does not have a numeric value, or
3020has no value, the default value is 10. If it does not exist,
3021<FONT SIZE=-1><B>EOF</B>
3022
3023</FONT>
3024signifies the end of input to the shell.
3025<DT><B>INPUTRC</B>
3026
3027<DD>
3028The filename for the
3029<B>readline</B>
3030
3031startup file, overriding the default of
3032
3033<A HREF="file:~/.inputrc"><I>~/.inputrc</I></A>
3034
3035(see
3036<FONT SIZE=-1><B>READLINE</B>
3037
3038</FONT>
3039below).
d233b485
CR
3040<DT><B>INSIDE_EMACS</B>
3041
3042<DD>
3043If this variable appears in the environment when the shell starts,
3044<B>bash</B> assumes that it is running inside an Emacs shell buffer
3045and may disable line editing, depending on the value of <B>TERM</B>.
17345e5a
JA
3046<DT><B>LANG</B>
3047
3048<DD>
3049Used to determine the locale category for any category not specifically
3050selected with a variable starting with <B>LC_</B>.
3051<DT><B>LC_ALL</B>
3052
3053<DD>
0001803f
CR
3054This variable overrides the value of
3055<FONT SIZE=-1><B>LANG</B>
3056
3057</FONT>
3058and any other
17345e5a
JA
3059<B>LC_</B> variable specifying a locale category.
3060<DT><B>LC_COLLATE</B>
3061
3062<DD>
3063This variable determines the collation order used when sorting the
3064results of pathname expansion, and determines the behavior of range
3065expressions, equivalence classes, and collating sequences within
3066pathname expansion and pattern matching.
3067<DT><B>LC_CTYPE</B>
3068
3069<DD>
3070This variable determines the interpretation of characters and the
3071behavior of character classes within pathname expansion and pattern
3072matching.
3073<DT><B>LC_MESSAGES</B>
3074
3075<DD>
3076This variable determines the locale used to translate double-quoted
3077strings preceded by a <B>$</B>.
3078<DT><B>LC_NUMERIC</B>
3079
3080<DD>
3081This variable determines the locale category used for number formatting.
a0c0a00f
CR
3082<DT><B>LC_TIME</B>
3083
3084<DD>
3085This variable determines the locale category used for data and time
3086formatting.
17345e5a
JA
3087<DT><B>LINES</B>
3088
3089<DD>
495aee44 3090Used by the <B>select</B> compound command to determine the column length
ac50fbac
CR
3091for printing selection lists.
3092Automatically set if the
3093<B>checkwinsize</B>
3094
3095option is enabled or in an interactive shell upon receipt of a
0001803f
CR
3096<FONT SIZE=-1><B>SIGWINCH</B>.
3097
3098</FONT>
17345e5a
JA
3099<DT><B>MAIL</B>
3100
3101<DD>
495aee44 3102If this parameter is set to a file or directory name and the
17345e5a
JA
3103<FONT SIZE=-1><B>MAILPATH</B>
3104
3105</FONT>
3106variable is not set,
3107<B>bash</B>
3108
495aee44
CR
3109informs the user of the arrival of mail in the specified file or
3110Maildir-format directory.
17345e5a
JA
3111<DT><B>MAILCHECK</B>
3112
3113<DD>
3114Specifies how
3115often (in seconds)
3116<B>bash</B>
3117
3118checks for mail. The default is 60 seconds. When it is time to check
3119for mail, the shell does so before displaying the primary prompt.
3120If this variable is unset, or set to a value that is not a number
3121greater than or equal to zero, the shell disables mail checking.
3122<DT><B>MAILPATH</B>
3123
3124<DD>
a0c0a00f 3125A colon-separated list of filenames to be checked for mail.
17345e5a 3126The message to be printed when mail arrives in a particular file
ac50fbac 3127may be specified by separating the filename from the message with a `?'.
17345e5a 3128When used in the text of the message, <B>$_</B> expands to the name of
a0c0a00f 3129the current mailfile.
17345e5a
JA
3130Example:
3131<DL COMPACT><DT><DD>
3132<P>
3133
3134<B>MAILPATH</B>=aq/var/mail/bfox?&quot;You have mail&quot;:~/shell-mail?&quot;$_ has mail!&quot;aq
3135<P>
3136
3137<B>Bash</B>
3138
a0c0a00f
CR
3139can be configured to supply
3140a default value for this variable (there is no value by default),
3141but the location of the user
17345e5a
JA
3142mail files that it uses is system dependent (e.g., /var/mail/<B>$USER</B>).
3143</DL>
3144
3145<DT><B>OPTERR</B>
3146
3147<DD>
3148If set to the value 1,
3149<B>bash</B>
3150
3151displays error messages generated by the
3152<B>getopts</B>
3153
3154builtin command (see
3155<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
3156
3157</FONT>
3158below).
3159<FONT SIZE=-1><B>OPTERR</B>
3160
3161</FONT>
3162is initialized to 1 each time the shell is invoked or a shell
3163script is executed.
3164<DT><B>PATH</B>
3165
3166<DD>
3167The search path for commands. It
3168is a colon-separated list of directories in which
3169the shell looks for commands (see
3170<FONT SIZE=-1><B>COMMAND EXECUTION</B>
3171
3172</FONT>
3173below).
0001803f
CR
3174A zero-length (null) directory name in the value of
3175<FONT SIZE=-1><B>PATH</B>
3176
3177</FONT>
3178indicates the current directory.
17345e5a
JA
3179A null directory name may appear as two adjacent colons, or as an initial
3180or trailing colon.
3181The default path is system-dependent,
3182and is set by the administrator who installs
3183<B>bash</B>.
3184
3185A common value is
a0c0a00f 3186
ac50fbac 3187<TT>/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin</TT>.
17345e5a 3188
a0c0a00f 3189
17345e5a
JA
3190<DT><B>POSIXLY_CORRECT</B>
3191
3192<DD>
3193If this variable is in the environment when <B>bash</B> starts, the shell
3194enters <I>posix mode</I> before reading the startup files, as if the
3195<B>--posix</B>
3196
3197invocation option had been supplied. If it is set while the shell is
3198running, <B>bash</B> enables <I>posix mode</I>, as if the command
3199<TT>set -o posix</TT>
3200
3201had been executed.
d233b485
CR
3202When the shell enters <I>posix mode</I>, it sets this variable if it was
3203not already set.
17345e5a
JA
3204<DT><B>PROMPT_COMMAND</B>
3205
3206<DD>
8868edaf
CR
3207If this variable is set, and is an array,
3208the value of each set element is executed as a command
3209prior to issuing each primary prompt.
3210If this is set but not an array variable,
3211its value is used as a command to execute instead.
17345e5a
JA
3212<DT><B>PROMPT_DIRTRIM</B>
3213
3214<DD>
3215If set to a number greater than zero, the value is used as the number of
0001803f
CR
3216trailing directory components to retain when expanding the <B>\w</B> and
3217<B>\W</B> prompt string escapes (see
17345e5a
JA
3218<FONT SIZE=-1><B>PROMPTING</B>
3219
3220</FONT>
3221below). Characters removed are replaced with an ellipsis.
a0c0a00f
CR
3222<DT><B>PS0</B>
3223
3224<DD>
3225The value of this parameter is expanded (see
3226<FONT SIZE=-1><B>PROMPTING</B>
3227
3228</FONT>
3229below) and displayed by interactive shells after reading a command
3230and before the command is executed.
17345e5a
JA
3231<DT><B>PS1</B>
3232
3233<DD>
3234The value of this parameter is expanded (see
3235<FONT SIZE=-1><B>PROMPTING</B>
3236
3237</FONT>
3238below) and used as the primary prompt string. The default value is
3239``<B>\s-\v\$ </B>''.
3240<DT><B>PS2</B>
3241
3242<DD>
3243The value of this parameter is expanded as with
0001803f 3244<FONT SIZE=-1><B>PS1</B>
17345e5a 3245
0001803f 3246</FONT>
17345e5a
JA
3247and used as the secondary prompt string. The default is
3248``<B>&gt; </B>''.
3249<DT><B>PS3</B>
3250
3251<DD>
3252The value of this parameter is used as the prompt for the
3253<B>select</B>
3254
3255command (see
3256<FONT SIZE=-1><B>SHELL GRAMMAR</B>
3257
3258</FONT>
3259above).
3260<DT><B>PS4</B>
3261
3262<DD>
3263The value of this parameter is expanded as with
0001803f 3264<FONT SIZE=-1><B>PS1</B>
17345e5a 3265
0001803f 3266</FONT>
17345e5a
JA
3267and the value is printed before each command
3268<B>bash</B>
3269
3270displays during an execution trace. The first character of
d233b485 3271the expanded value of
17345e5a
JA
3272<FONT SIZE=-1><B>PS4</B>
3273
3274</FONT>
3275is replicated multiple times, as necessary, to indicate multiple
3276levels of indirection. The default is ``<B>+ </B>''.
3277<DT><B>SHELL</B>
3278
3279<DD>
8868edaf 3280This variable expands to the full pathname to the shell.
17345e5a
JA
3281If it is not set when the shell starts,
3282<B>bash</B>
3283
3284assigns to it the full pathname of the current user's login shell.
3285<DT><B>TIMEFORMAT</B>
3286
3287<DD>
3288The value of this parameter is used as a format string specifying
3289how the timing information for pipelines prefixed with the
3290<B>time</B>
3291
3292reserved word should be displayed.
3293The <B>%</B> character introduces an escape sequence that is
3294expanded to a time value or other information.
3295The escape sequences and their meanings are as follows; the
3296braces denote optional portions.
3297<P>
3298<DL COMPACT><DT><DD>
3299
3300<DL COMPACT>
3301<DT><B>%%</B>
3302
3303<DD>
3304A literal <B>%</B>.
3305<DT><B>%[</B><I>p</I>][l]R
3306
3307<DD>
3308The elapsed time in seconds.
3309<DT><B>%[</B><I>p</I>][l]U
3310
3311<DD>
3312The number of CPU seconds spent in user mode.
3313<DT><B>%[</B><I>p</I>][l]S
3314
3315<DD>
3316The number of CPU seconds spent in system mode.
3317<DT><B>%P</B>
3318
3319<DD>
3320The CPU percentage, computed as (%U + %S) / %R.
3321
3322</DL></DL>
3323
3324<DT><DD>
3325The optional <I>p</I> is a digit specifying the <I>precision</I>,
3326the number of fractional digits after a decimal point.
3327A value of 0 causes no decimal point or fraction to be output.
3328At most three places after the decimal point may be specified;
3329values of <I>p</I> greater than 3 are changed to 3.
3330If <I>p</I> is not specified, the value 3 is used.
3331<DT><DD>
3332The optional <B>l</B> specifies a longer format, including
3333minutes, of the form <I>MM</I>m<I>SS</I>.<I>FF</I>s.
3334The value of <I>p</I> determines whether or not the fraction is
3335included.
3336<DT><DD>
3337If this variable is not set, <B>bash</B> acts as if it had the
ac50fbac 3338value <B>$aq\nreal\t%3lR\nuser\t%3lU\nsys\t%3lSaq</B>.
17345e5a
JA
3339If the value is null, no timing information is displayed.
3340A trailing newline is added when the format string is displayed.
ac50fbac 3341
17345e5a
JA
3342<DT><B>TMOUT</B>
3343
3344<DD>
0001803f
CR
3345If set to a value greater than zero,
3346<FONT SIZE=-1><B>TMOUT</B>
3347
3348</FONT>
3349is treated as the
17345e5a
JA
3350default timeout for the <B>read</B> builtin.
3351The <B>select</B> command terminates if input does not arrive
0001803f
CR
3352after
3353<FONT SIZE=-1><B>TMOUT</B>
3354
3355</FONT>
3356seconds when input is coming from a terminal.
17345e5a 3357In an interactive shell, the value is interpreted as the
ac50fbac
CR
3358number of seconds to wait for a line of input after issuing the
3359primary prompt.
17345e5a
JA
3360<B>Bash</B>
3361
ac50fbac
CR
3362terminates after waiting for that number of seconds if a complete
3363line of input does not arrive.
17345e5a
JA
3364<DT><B>TMPDIR</B>
3365
3366<DD>
495aee44
CR
3367If set, <B>bash</B> uses its value as the name of a directory in which
3368<B>bash</B> creates temporary files for the shell's use.
17345e5a
JA
3369<DT><B>auto_resume</B>
3370
3371<DD>
3372This variable controls how the shell interacts with the user and
3373job control. If this variable is set, single word simple
3374commands without redirections are treated as candidates for resumption
3375of an existing stopped job. There is no ambiguity allowed; if there is
3376more than one job beginning with the string typed, the job most recently
3377accessed is selected. The
3378<I>name</I>
3379
3380of a stopped job, in this context, is the command line used to
3381start it.
3382If set to the value
3383<I>exact</I>,
3384
3385the string supplied must match the name of a stopped job exactly;
3386if set to
3387<I>substring</I>,
3388
3389the string supplied needs to match a substring of the name of a
3390stopped job. The
3391<I>substring</I>
3392
3393value provides functionality analogous to the
3394<B>%?</B>
3395
3396job identifier (see
3397<FONT SIZE=-1><B>JOB CONTROL</B>
3398
3399</FONT>
3400below). If set to any other value, the supplied string must
3401be a prefix of a stopped job's name; this provides functionality
3402analogous to the <B>%</B><I>string</I> job identifier.
3403<DT><B>histchars</B>
3404
3405<DD>
3406The two or three characters which control history expansion
3407and tokenization (see
3408<FONT SIZE=-1><B>HISTORY EXPANSION</B>
3409
3410</FONT>
3411below). The first character is the <I>history expansion</I> character,
3412the character which signals the start of a history
3413expansion, normally `<B>!</B>'.
3414The second character is the <I>quick substitution</I>
3415character, which is used as shorthand for re-running the previous
3416command entered, substituting one string for another in the command.
3417The default is `<B>^</B>'.
3418The optional third character is the character
3419which indicates that the remainder of the line is a comment when found
3420as the first character of a word, normally `<B>#</B>'. The history
3421comment character causes history substitution to be skipped for the
3422remaining words on the line. It does not necessarily cause the shell
3423parser to treat the rest of the line as a comment.
3424
3425</DL>
3426<A NAME="lbAX">&nbsp;</A>
3427<H4>Arrays</H4>
3428
3429<B>Bash</B>
3430
3431provides one-dimensional indexed and associative array variables.
3432Any variable may be used as an indexed array; the
3433<B>declare</B>
3434
3435builtin will explicitly declare an array.
3436There is no maximum
3437limit on the size of an array, nor any requirement that members
3438be indexed or assigned contiguously.
3439Indexed arrays are referenced using integers (including arithmetic
a0c0a00f 3440expressions) and are zero-based; associative arrays are referenced
17345e5a 3441using arbitrary strings.
ac50fbac 3442Unless otherwise noted, indexed array indices must be non-negative integers.
17345e5a
JA
3443<P>
3444
3445An indexed array is created automatically if any variable is assigned to
3446using the syntax <I>name</I>[<I>subscript</I>]=<I>value</I>. The
3447<I>subscript</I>
3448
495aee44 3449is treated as an arithmetic expression that must evaluate to a number.
495aee44 3450To explicitly declare an indexed array, use
17345e5a
JA
3451<B>declare -a </B><I>name</I>
3452
3453(see
3454<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
3455
3456</FONT>
3457below).
3458<B>declare -a </B><I>name</I>[<I>subscript</I>]
3459
3460is also accepted; the <I>subscript</I> is ignored.
3461<P>
3462
3463Associative arrays are created using
3464<B>declare -A </B><I>name</I>.
3465
3466<P>
3467
3468Attributes may be
3469specified for an array variable using the
3470<B>declare</B>
3471
3472and
3473<B>readonly</B>
3474
3475builtins. Each attribute applies to all members of an array.
3476<P>
3477
3478Arrays are assigned to using compound assignments of the form
3479<I>name</I>=<B>(</B>value<I>1</I> ... value<I>n</I><B>)</B>, where each
8868edaf 3480<I>value</I> may be of the form [<I>subscript</I>]=<I>string</I>.
ac50fbac 3481Indexed array assignments do not require anything but <I>string</I>.
8868edaf
CR
3482Each <I>value</I> in the list is expanded using all the shell expansions
3483described below under
3484<FONT SIZE=-1><B>EXPANSION</B>.
3485
3486</FONT>
17345e5a
JA
3487When assigning to indexed arrays, if the optional brackets and subscript
3488are supplied, that index is assigned to;
3489otherwise the index of the element assigned is the last index assigned
3490to by the statement plus one. Indexing starts at zero.
3491<P>
3492
8868edaf
CR
3493When assigning to an associative array, the words in a compound assignment
3494may be either assignment statements, for which the subscript is required,
3495or a list of words that is interpreted as a sequence of alternating keys
3496and values:
3497<I>name</I>=<B>( </B><I>key1 value1 key2 value2</I> ...<B>)</B>.
3498These are treated identically to
3499<I>name</I>=<B>(</B> [<I>key1</I>]=<I>value1</I> [<I>key2</I>]=<I>value2</I> ...<B>)</B>.
3500The first word in the list determines how the remaining words
3501are interpreted; all assignments in a list must be of the same type.
3502When using key/value pairs, the keys may not be missing or empty;
3503a final missing value is treated like the empty string.
17345e5a
JA
3504<P>
3505
3506This syntax is also accepted by the
3507<B>declare</B>
3508
3509builtin. Individual array elements may be assigned to using the
3510<I>name</I>[<I>subscript</I>]=<I>value</I> syntax introduced above.
ac50fbac
CR
3511When assigning to an indexed array, if
3512<I>name</I>
3513
3514is subscripted by a negative number, that number is
3515interpreted as relative to one greater than the maximum index of
3516<I>name</I>, so negative indices count back from the end of the
3517array, and an index of -1 references the last element.
17345e5a
JA
3518<P>
3519
74091dd4
CR
3520The += operator will append to an array variable when assigning
3521using the compound assignment syntax; see
3522<FONT SIZE=-1><B>PARAMETERS</B>
3523
3524</FONT>
3525above.
3526<P>
3527
17345e5a
JA
3528Any element of an array may be referenced using
3529${<I>name</I>[<I>subscript</I>]}. The braces are required to avoid
3530conflicts with pathname expansion. If
3531<I>subscript</I> is <B>@</B> or <B>*</B>, the word expands to
3532all members of <I>name</I>. These subscripts differ only when the
3533word appears within double quotes. If the word is double-quoted,
3534${<I>name</I>[*]} expands to a single
3535word with the value of each array member separated by the first
3536character of the
3537<FONT SIZE=-1><B>IFS</B>
3538
3539</FONT>
3540special variable, and ${<I>name</I>[@]} expands each element of
3541<I>name</I> to a separate word. When there are no array members,
3542${<I>name</I>[@]} expands to nothing.
3543If the double-quoted expansion occurs within a word, the expansion of
3544the first parameter is joined with the beginning part of the original
3545word, and the expansion of the last parameter is joined with the last
3546part of the original word.
3547This is analogous to the expansion
3548of the special parameters <B>*</B> and <B>@</B> (see
3549<B>Special Parameters</B>
3550
3551above). ${#<I>name</I>[<I>subscript</I>]} expands to the length of
3552${<I>name</I>[<I>subscript</I>]}. If <I>subscript</I> is <B>*</B> or
3553<B>@</B>, the expansion is the number of elements in the array.
ac50fbac
CR
3554If the
3555<I>subscript</I>
3556
3557used to reference an element of an indexed array
a0c0a00f 3558evaluates to a number less than zero, it is
ac50fbac
CR
3559interpreted as relative to one greater than the maximum index of the array,
3560so negative indices count back from the end of the
3561array, and an index of -1 references the last element.
17345e5a
JA
3562<P>
3563
a0c0a00f
CR
3564Referencing an array variable without a subscript is equivalent to
3565referencing the array with a subscript of 0.
3566Any reference to a variable using a valid subscript is legal, and
3567<B>bash</B>
3568
3569will create an array if necessary.
3570<P>
3571
0001803f
CR
3572An array variable is considered set if a subscript has been assigned a
3573value. The null string is a valid value.
3574<P>
3575
ac50fbac
CR
3576It is possible to obtain the keys (indices) of an array as well as the values.
3577${<B>!</B><I>name</I>[<I>@</I>]} and ${<B>!</B><I>name</I>[<I>*</I>]}
3578expand to the indices assigned in array variable <I>name</I>.
3579The treatment when in double quotes is similar to the expansion of the
3580special parameters <I>@</I> and <I>*</I> within double quotes.
3581<P>
3582
17345e5a
JA
3583The
3584<B>unset</B>
3585
3586builtin is used to destroy arrays. <B>unset</B> <I>name</I>[<I>subscript</I>]
d233b485
CR
3587destroys the array element at index <I>subscript</I>,
3588for both indexed and associative arrays.
ac50fbac 3589Negative subscripts to indexed arrays are interpreted as described above.
d233b485 3590Unsetting the last element of an array variable does not unset the variable.
74091dd4
CR
3591<B>unset</B> <I>name</I>, where <I>name</I> is an array,
3592removes the entire array.
17345e5a 3593<B>unset</B> <I>name</I>[<I>subscript</I>], where
74091dd4
CR
3594<I>subscript</I> is <B>*</B> or <B>@</B>, behaves differently depending on
3595whether <I>name</I> is an indexed or associative array.
3596If <I>name</I> is an associative array, this unsets the element with
3597subscript <B>*</B> or <B>@</B>.
3598If <I>name</I> is an indexed array, unset removes all of the elements but
3599does not remove the array itself.
17345e5a
JA
3600<P>
3601
d233b485
CR
3602When using a variable name with a subscript as an argument to a command,
3603such as with <B>unset</B>, without using the word expansion syntax
3604described above, the argument is subject to pathname expansion.
3605If pathname expansion is not desired, the argument should be quoted.
3606<P>
3607
17345e5a
JA
3608The
3609<B>declare</B>,
3610
3611<B>local</B>,
3612
3613and
3614<B>readonly</B>
3615
3616builtins each accept a
3617<B>-a</B>
3618
3619option to specify an indexed array and a
3620<B>-A</B>
3621
3622option to specify an associative array.
a0c0a00f 3623If both options are supplied,
ac50fbac
CR
3624<B>-A</B>
3625
3626takes precedence.
17345e5a
JA
3627The
3628<B>read</B>
3629
3630builtin accepts a
3631<B>-a</B>
3632
3633option to assign a list of words read from the standard input
3634to an array. The
3635<B>set</B>
3636
3637and
3638<B>declare</B>
3639
3640builtins display array values in a way that allows them to be
3641reused as assignments.
3642<A NAME="lbAY">&nbsp;</A>
3643<H3>EXPANSION</H3>
3644
3645Expansion is performed on the command line after it has been split into
3646words. There are seven kinds of expansion performed:
3647<I>brace expansion</I>,
3648
3649<I>tilde expansion</I>,
3650
3651<I>parameter and variable expansion</I>,
3652
3653<I>command substitution</I>,
3654
3655<I>arithmetic expansion</I>,
3656
3657<I>word splitting</I>,
3658
3659and
3660<I>pathname expansion</I>.
3661
3662<P>
3663
ac50fbac
CR
3664The order of expansions is:
3665brace expansion;
3666tilde expansion, parameter and variable expansion, arithmetic expansion,
3667and command substitution (done in a left-to-right fashion);
3668word splitting;
3669and pathname expansion.
17345e5a
JA
3670<P>
3671
3672On systems that can support it, there is an additional expansion
3673available: <I>process substitution</I>.
ac50fbac
CR
3674This is performed at the
3675same time as tilde, parameter, variable, and arithmetic expansion and
3676command substitution.
17345e5a
JA
3677<P>
3678
a0c0a00f
CR
3679After these expansions are performed, quote characters present in the
3680original word are removed unless they have been quoted themselves
3681(<I>quote removal</I>).
3682<P>
3683
17345e5a 3684Only brace expansion, word splitting, and pathname expansion
d233b485 3685can increase the number of words of the expansion; other expansions
17345e5a
JA
3686expand a single word to a single word.
3687The only exceptions to this are the expansions of
d233b485
CR
3688&quot;<B>$@</B>&quot; and &quot;<B>${</B><I>name</I><B>[@]}</B>&quot;,
3689and, in most cases, <B>$*</B> and <B>${</B><I>name</I><B>[*]}</B>
17345e5a
JA
3690as explained above (see
3691<FONT SIZE=-1><B>PARAMETERS</B>).
3692
3693</FONT>
3694<A NAME="lbAZ">&nbsp;</A>
3695<H4>Brace Expansion</H4>
3696
17345e5a
JA
3697<I>Brace expansion</I>
3698
3699is a mechanism by which arbitrary strings
3700may be generated. This mechanism is similar to
3701<I>pathname expansion</I>, but the filenames generated
3702need not exist. Patterns to be brace expanded take
3703the form of an optional
3704<I>preamble</I>,
3705
3706followed by either a series of comma-separated strings or
3707a sequence expression between a pair of braces, followed by
3708an optional
3709<I>postscript</I>.
3710
3711The preamble is prefixed to each string contained
3712within the braces, and the postscript is then appended
3713to each resulting string, expanding left to right.
3714<P>
3715
3716Brace expansions may be nested. The results of each expanded
3717string are not sorted; left to right order is preserved.
3718For example, a<B>{</B>d,c,b<B>}</B>e expands into `ade ace abe'.
3719<P>
3720
3721A sequence expression takes the form
3722<B>{</B><I>x</I><B>..</B><I>y</I><B>[..</B><I>incr</I><B>]}</B>,
74091dd4 3723where <I>x</I> and <I>y</I> are either integers or single letters,
17345e5a
JA
3724and <I>incr</I>, an optional increment, is an integer.
3725When integers are supplied, the expression expands to each number between
3726<I>x</I> and <I>y</I>, inclusive.
3727Supplied integers may be prefixed with <I>0</I> to force each term to have the
ac50fbac
CR
3728same width.
3729When either <I>x</I> or y begins with a zero, the shell
17345e5a
JA
3730attempts to force all generated terms to contain the same number of digits,
3731zero-padding where necessary.
74091dd4 3732When letters are supplied, the expression expands to each character
ac50fbac
CR
3733lexicographically between <I>x</I> and <I>y</I>, inclusive,
3734using the default C locale.
74091dd4
CR
3735Note that both <I>x</I> and <I>y</I> must be of the same type
3736(integer or letter).
17345e5a
JA
3737When the increment is supplied, it is used as the difference between
3738each term. The default increment is 1 or -1 as appropriate.
3739<P>
3740
3741Brace expansion is performed before any other expansions,
3742and any characters special to other expansions are preserved
3743in the result. It is strictly textual.
3744<B>Bash</B>
3745
3746does not apply any syntactic interpretation to the context of the
3747expansion or the text between the braces.
3748<P>
3749
3750A correctly-formed brace expansion must contain unquoted opening
3751and closing braces, and at least one unquoted comma or a valid
3752sequence expression.
3753Any incorrectly formed brace expansion is left unchanged.
3754A <B>{</B> or <B>,</B> may be quoted with a backslash to prevent its
3755being considered part of a brace expression.
3756To avoid conflicts with parameter expansion, the string <B>${</B>
d233b485
CR
3757is not considered eligible for brace expansion, and inhibits brace
3758expansion until the closing <B>}</B>.
17345e5a
JA
3759<P>
3760
3761This construct is typically used as shorthand when the common
3762prefix of the strings to be generated is longer than in the
3763above example:
3764<DL COMPACT><DT><DD>
3765<P>
3766
3767mkdir /usr/local/src/bash/{old,new,dist,bugs}
3768</DL>
3769
3770or
3771<DL COMPACT><DT><DD>
3772chown root /usr/{ucb/{ex,edit},lib/{ex?.?*,how_ex}}
3773</DL>
3774
3775<P>
3776
3777Brace expansion introduces a slight incompatibility with
3778historical versions of
3779<B>sh</B>.
3780
3781<B>sh</B>
3782
3783does not treat opening or closing braces specially when they
3784appear as part of a word, and preserves them in the output.
3785<B>Bash</B>
3786
3787removes braces from words as a consequence of brace
3788expansion. For example, a word entered to
3789<B>sh</B>
3790
3791as <I>file{1,2}</I>
3792appears identically in the output. The same word is
3793output as
3794<I>file1 file2</I>
3795
3796after expansion by
3797<B>bash</B>.
3798
3799If strict compatibility with
3800<B>sh</B>
3801
3802is desired, start
3803<B>bash</B>
3804
3805with the
a0c0a00f 3806<B>+B</B>
17345e5a
JA
3807
3808option or disable brace expansion with the
3809<B>+B</B>
3810
3811option to the
3812<B>set</B>
3813
3814command (see
3815<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
3816
3817</FONT>
3818below).
3819<A NAME="lbBA">&nbsp;</A>
3820<H4>Tilde Expansion</H4>
3821
17345e5a
JA
3822If a word begins with an unquoted tilde character (`<B>~</B>'), all of
3823the characters preceding the first unquoted slash (or all characters,
3824if there is no unquoted slash) are considered a <I>tilde-prefix</I>.
3825If none of the characters in the tilde-prefix are quoted, the
3826characters in the tilde-prefix following the tilde are treated as a
3827possible <I>login name</I>.
3828If this login name is the null string, the tilde is replaced with the
3829value of the shell parameter
3830<FONT SIZE=-1><B>HOME</B>.
3831
3832</FONT>
3833If
3834<FONT SIZE=-1><B>HOME</B>
3835
3836</FONT>
3837is unset, the home directory of the user executing the shell is
3838substituted instead.
3839Otherwise, the tilde-prefix is replaced with the home directory
3840associated with the specified login name.
3841<P>
3842
3843If the tilde-prefix is a `~+', the value of the shell variable
3844<FONT SIZE=-1><B>PWD</B>
3845
3846</FONT>
3847replaces the tilde-prefix.
3848If the tilde-prefix is a `~-', the value of the shell variable
3849<FONT SIZE=-1><B>OLDPWD</B>,
3850
3851</FONT>
3852if it is set, is substituted.
3853If the characters following the tilde in the tilde-prefix consist
3854of a number <I>N</I>, optionally prefixed
3855by a `+' or a `-', the tilde-prefix is replaced with the corresponding
3856element from the directory stack, as it would be displayed by the
3857<B>dirs</B>
3858
3859builtin invoked with the tilde-prefix as an argument.
3860If the characters following the tilde in the tilde-prefix consist of a
3861number without a leading `+' or `-', `+' is assumed.
3862<P>
3863
3864If the login name is invalid, or the tilde expansion fails, the word
3865is unchanged.
3866<P>
3867
3868Each variable assignment is checked for unquoted tilde-prefixes immediately
3869following a
3870<B>:</B>
3871
3872or the first
3873<B>=</B>.
3874
3875In these cases, tilde expansion is also performed.
ac50fbac 3876Consequently, one may use filenames with tildes in assignments to
17345e5a
JA
3877<FONT SIZE=-1><B>PATH</B>,
3878
3879</FONT>
3880<FONT SIZE=-1><B>MAILPATH</B>,
3881
3882</FONT>
3883and
3884<FONT SIZE=-1><B>CDPATH</B>,
3885
3886</FONT>
3887and the shell assigns the expanded value.
d233b485
CR
3888<P>
3889
3890Bash also performs tilde expansion on words satisfying the conditions of
3891variable assignments (as described above under
3892<FONT SIZE=-1><B>PARAMETERS</B>)
3893
3894</FONT>
3895when they appear as arguments to simple commands.
3896Bash does not do this, except for the <I>declaration</I> commands listed
3897above, when in <I>posix mode</I>.
17345e5a
JA
3898<A NAME="lbBB">&nbsp;</A>
3899<H4>Parameter Expansion</H4>
3900
17345e5a
JA
3901The `<B>$</B>' character introduces parameter expansion,
3902command substitution, or arithmetic expansion. The parameter name
3903or symbol to be expanded may be enclosed in braces, which
3904are optional but serve to protect the variable to be expanded from
3905characters immediately following it which could be
3906interpreted as part of the name.
3907<P>
3908
3909When braces are used, the matching ending brace is the first `<B>}</B>'
3910not escaped by a backslash or within a quoted string, and not within an
3911embedded arithmetic expansion, command substitution, or parameter
3912expansion.
3913<P>
3914
3915
3916<DL COMPACT>
3917<DT>${<I>parameter</I>}<DD>
3918The value of <I>parameter</I> is substituted. The braces are required
3919when
3920<I>parameter</I>
3921
3922is a positional parameter with more than one digit,
3923or when
3924<I>parameter</I>
3925
3926is followed by a character which is not to be
3927interpreted as part of its name.
ac50fbac
CR
3928The <I>parameter</I> is a shell parameter as described above
3929<B>PARAMETERS</B>) or an array reference (<B>Arrays</B>).
17345e5a
JA
3930
3931</DL>
3932<P>
3933
0001803f 3934If the first character of <I>parameter</I> is an exclamation point (<B>!</B>),
a0c0a00f 3935and <I>parameter</I> is not a <I>nameref</I>,
d233b485
CR
3936it introduces a level of indirection.
3937<B>Bash</B> uses the value formed by expanding the rest of
3938<I>parameter</I> as the new <I>parameter</I>; this is then
3939expanded and that value is used in the rest of the expansion, rather
3940than the expansion of the original <I>parameter</I>.
17345e5a 3941This is known as <I>indirect expansion</I>.
d233b485
CR
3942The value is subject to tilde expansion,
3943parameter expansion, command substitution, and arithmetic expansion.
a0c0a00f 3944If <I>parameter</I> is a nameref, this expands to the name of the
d233b485 3945parameter referenced by <I>parameter</I> instead of performing the
a0c0a00f 3946complete indirect expansion.
ac50fbac 3947The exceptions to this are the expansions of ${<B>!</B><I>prefix</I><B>*</B>} and
17345e5a
JA
3948${<B>!</B><I>name</I>[<I>@</I>]} described below.
3949The exclamation point must immediately follow the left brace in order to
3950introduce indirection.
3951<P>
3952
3953In each of the cases below, <I>word</I> is subject to tilde expansion,
3954parameter expansion, command substitution, and arithmetic expansion.
3955<P>
3956
ac50fbac
CR
3957When not performing substring expansion, using the forms documented below
3958(e.g., <B>:-</B>),
17345e5a
JA
3959<B>bash</B> tests for a parameter that is unset or null. Omitting the colon
3960results in a test only for a parameter that is unset.
3961<P>
3962
3963
3964<DL COMPACT>
3965<DT>${<I>parameter</I><B>:-</B><I>word</I>}<DD>
3966<B>Use Default Values</B>. If
3967<I>parameter</I>
3968
3969is unset or null, the expansion of
3970<I>word</I>
3971
3972is substituted. Otherwise, the value of
3973<I>parameter</I>
3974
3975is substituted.
3976<DT>${<I>parameter</I><B>:=</B><I>word</I>}<DD>
3977<B>Assign Default Values</B>.
3978If
3979<I>parameter</I>
3980
3981is unset or null, the expansion of
3982<I>word</I>
3983
3984is assigned to
3985<I>parameter</I>.
3986
3987The value of
3988<I>parameter</I>
3989
3990is then substituted. Positional parameters and special parameters may
3991not be assigned to in this way.
3992<DT>${<I>parameter</I><B>:?</B><I>word</I>}<DD>
3993<B>Display Error if Null or Unset</B>.
3994If
3995<I>parameter</I>
3996
3997is null or unset, the expansion of <I>word</I> (or a message to that effect
3998if
3999<I>word</I>
4000
4001is not present) is written to the standard error and the shell, if it
4002is not interactive, exits. Otherwise, the value of <I>parameter</I> is
4003substituted.
4004<DT>${<I>parameter</I><B>:+</B><I>word</I>}<DD>
4005<B>Use Alternate Value</B>.
4006If
4007<I>parameter</I>
4008
4009is null or unset, nothing is substituted, otherwise the expansion of
4010<I>word</I>
4011
4012is substituted.
4013<DT>${<I>parameter</I><B>:</B><I>offset</I>}<DD>
4014
4015<DT>${<I>parameter</I><B>:</B><I>offset</I><B>:</B><I>length</I>}<DD>
4016
495aee44 4017<B>Substring Expansion</B>.
ac50fbac 4018Expands to up to <I>length</I> characters of the value of <I>parameter</I>
17345e5a 4019starting at the character specified by <I>offset</I>.
74091dd4 4020If <I>parameter</I> is <B>@</B> or <B>*</B>, an indexed array subscripted by
ac50fbac
CR
4021<B>@</B> or <B>*</B>, or an associative array name, the results differ as
4022described below.
4023If <I>length</I> is omitted, expands to the substring of the value of
4024<I>parameter</I> starting at the character specified by <I>offset</I>
4025and extending to the end of the value.
17345e5a
JA
4026<I>length</I> and <I>offset</I> are arithmetic expressions (see
4027<FONT SIZE=-1><B>ARITHMETIC EVALUATION</B>
4028
4029</FONT>
4030below).
ac50fbac 4031<P>
17345e5a 4032If <I>offset</I> evaluates to a number less than zero, the value
ac50fbac
CR
4033is used as an offset in characters
4034from the end of the value of <I>parameter</I>.
4035If <I>length</I> evaluates to a number less than zero,
4036it is interpreted as an offset in characters
4037from the end of the value of <I>parameter</I> rather than
4038a number of characters, and the expansion is the characters between
4039<I>offset</I> and that result.
4040Note that a negative offset must be separated from the colon by at least
4041one space to avoid being confused with the <B>:-</B> expansion.
4042<P>
74091dd4
CR
4043If <I>parameter</I> is <B>@</B> or <B>*</B>, the result is <I>length</I>
4044positional parameters beginning at <I>offset</I>.
ac50fbac
CR
4045A negative <I>offset</I> is taken relative to one greater than the greatest
4046positional parameter, so an offset of -1 evaluates to the last positional
4047parameter.
4048It is an expansion error if <I>length</I> evaluates to a number less than
4049zero.
4050<P>
17345e5a
JA
4051If <I>parameter</I> is an indexed array name subscripted by @ or *,
4052the result is the <I>length</I>
4053members of the array beginning with ${<I>parameter</I>[<I>offset</I>]}.
4054A negative <I>offset</I> is taken relative to one greater than the maximum
4055index of the specified array.
ac50fbac
CR
4056It is an expansion error if <I>length</I> evaluates to a number less than
4057zero.
4058<P>
17345e5a
JA
4059Substring expansion applied to an associative array produces undefined
4060results.
ac50fbac 4061<P>
a0c0a00f 4062Substring indexing is zero-based unless the positional parameters
17345e5a
JA
4063are used, in which case the indexing starts at 1 by default.
4064If <I>offset</I> is 0, and the positional parameters are used, <B>$0</B> is
4065prefixed to the list.
4066<DT>${<B>!</B><I>prefix</I><B>*</B>}<DD>
4067
4068<DT>${<B>!</B><I>prefix</I><B>@</B>}<DD>
4069
495aee44 4070<B>Names matching prefix</B>.
17345e5a
JA
4071Expands to the names of variables whose names begin with <I>prefix</I>,
4072separated by the first character of the
4073<FONT SIZE=-1><B>IFS</B>
4074
4075</FONT>
4076special variable.
4077When <I>@</I> is used and the expansion appears within double quotes, each
4078variable name expands to a separate word.
4079<DT>${<B>!</B><I>name</I>[<I>@</I>]}<DD>
4080
4081<DT>${<B>!</B><I>name</I>[<I>*</I>]}<DD>
4082
495aee44 4083<B>List of array keys</B>.
17345e5a
JA
4084If <I>name</I> is an array variable, expands to the list of array indices
4085(keys) assigned in <I>name</I>.
4086If <I>name</I> is not an array, expands to 0 if <I>name</I> is set and null
4087otherwise.
4088When <I>@</I> is used and the expansion appears within double quotes, each
4089key expands to a separate word.
4090<DT>${<B>#</B><I>parameter</I>}<DD>
495aee44 4091<B>Parameter length</B>.
17345e5a
JA
4092The length in characters of the value of <I>parameter</I> is substituted.
4093If
4094<I>parameter</I>
4095
4096is
4097<B>*</B>
4098
a0c0a00f 4099or
17345e5a
JA
4100<B>@</B>,
4101
4102the value substituted is the number of positional parameters.
4103If
4104<I>parameter</I>
4105
4106is an array name subscripted by
4107<B>*</B>
4108
4109or
4110<B>@</B>,
4111
4112the value substituted is the number of elements in the array.
ac50fbac
CR
4113If
4114<I>parameter</I>
4115
4116is an indexed array name subscripted by a negative number, that number is
4117interpreted as relative to one greater than the maximum index of
4118<I>parameter</I>, so negative indices count back from the end of the
4119array, and an index of -1 references the last element.
17345e5a
JA
4120<DT>${<I>parameter</I><B>#</B><I>word</I>}<DD>
4121
4122<DT>${<I>parameter</I><B>##</B><I>word</I>}<DD>
4123
495aee44 4124<B>Remove matching prefix pattern</B>.
a0c0a00f 4125The
17345e5a
JA
4126<I>word</I>
4127
4128is expanded to produce a pattern just as in pathname
d233b485
CR
4129expansion, and matched against the expanded value of
4130<I>parameter</I>
4131
4132using the rules described under
4133<B>Pattern Matching</B>
4134
4135below.
4136If the pattern matches the beginning of
17345e5a
JA
4137the value of
4138<I>parameter</I>,
4139
4140then the result of the expansion is the expanded value of
4141<I>parameter</I>
4142
4143with the shortest matching pattern (the ``<B>#</B>'' case) or the
4144longest matching pattern (the ``<B>##</B>'' case) deleted.
4145If
4146<I>parameter</I>
4147
4148is
4149<B>@</B>
4150
4151or
4152<B>*</B>,
4153
4154the pattern removal operation is applied to each positional
4155parameter in turn, and the expansion is the resultant list.
4156If
4157<I>parameter</I>
4158
4159is an array variable subscripted with
4160<B>@</B>
4161
4162or
4163<B>*</B>,
4164
4165the pattern removal operation is applied to each member of the
4166array in turn, and the expansion is the resultant list.
4167<DT>${<I>parameter</I><B>%</B><I>word</I>}<DD>
4168
4169<DT>${<I>parameter</I><B>%%</B><I>word</I>}<DD>
4170
495aee44 4171<B>Remove matching suffix pattern</B>.
17345e5a 4172The <I>word</I> is expanded to produce a pattern just as in
d233b485
CR
4173pathname expansion, and matched against the expanded value of
4174<I>parameter</I>
4175
4176using the rules described under
4177<B>Pattern Matching</B>
4178
4179below.
17345e5a
JA
4180If the pattern matches a trailing portion of the expanded value of
4181<I>parameter</I>,
4182
4183then the result of the expansion is the expanded value of
4184<I>parameter</I>
4185
4186with the shortest matching pattern (the ``<B>%</B>'' case) or the
4187longest matching pattern (the ``<B>%%</B>'' case) deleted.
4188If
4189<I>parameter</I>
4190
4191is
4192<B>@</B>
4193
4194or
4195<B>*</B>,
4196
4197the pattern removal operation is applied to each positional
4198parameter in turn, and the expansion is the resultant list.
4199If
4200<I>parameter</I>
4201
4202is an array variable subscripted with
4203<B>@</B>
4204
4205or
4206<B>*</B>,
4207
4208the pattern removal operation is applied to each member of the
4209array in turn, and the expansion is the resultant list.
4210<DT>${<I>parameter</I><B>/</B><I>pattern</I><B>/</B><I>string</I>}<DD>
74091dd4
CR
4211
4212<DT>${<I>parameter</I><B>//</B><I>pattern</I><B>/</B><I>string</I>}<DD>
4213<DT>${<I>parameter</I><B>/#</B><I>pattern</I><B>/</B><I>string</I>}<DD>
4214<DT>${<I>parameter</I><B>/%</B><I>pattern</I><B>/</B><I>string</I>}<DD>
4215
495aee44 4216<B>Pattern substitution</B>.
17345e5a 4217The <I>pattern</I> is expanded to produce a pattern just as in
74091dd4 4218pathname expansion.
17345e5a
JA
4219<I>Parameter</I> is expanded and the longest match of <I>pattern</I>
4220against its value is replaced with <I>string</I>.
74091dd4
CR
4221<I>string</I> undergoes tilde expansion, parameter and variable expansion,
4222arithmetic expansion, command and process substitution, and quote removal.
d233b485
CR
4223The match is performed using the rules described under
4224<B>Pattern Matching</B>
4225
4226below.
74091dd4
CR
4227In the first form above, only the first match is replaced.
4228If there are two slashes separating <I>parameter</I> and <I>pattern</I>
4229(the second form above), all matches of <I>pattern</I> are
4230replaced with <I>string</I>.
4231If <I>pattern</I> is preceded by <B>#</B> (the third form above),
4232it must match at the beginning of the expanded value of <I>parameter</I>.
4233If <I>pattern</I> is preceded by <B>%</B> (the fourth form above),
4234it must match at the end of the expanded value of <I>parameter</I>.
4235If the expansion of <I>string</I> is null,
4236matches of <I>pattern</I> are deleted.
4237If <I>string</I> is null,
4238matches of <I>pattern</I> are deleted
17345e5a 4239and the <B>/</B> following <I>pattern</I> may be omitted.
74091dd4
CR
4240<P>
4241If the <B>patsub_replacement</B> shell option is enabled using <B>shopt</B>,
4242any unquoted instances of <B>&amp;</B> in <I>string</I> are replaced with the
4243matching portion of <I>pattern</I>.
4244<P>
4245Quoting any part of <I>string</I> inhibits replacement in the
4246expansion of the quoted portion, including replacement strings stored
4247in shell variables.
4248Backslash will escape <B>&amp;</B> in <I>string</I>; the backslash is removed
4249in order to permit a literal <B>&amp;</B> in the replacement string.
4250Backslash can also be used to escape a backslash; <B>\\</B> results in
4251a literal backslash in the replacement.
4252Users should take care if <I>string</I> is double-quoted to avoid
4253unwanted interactions between the backslash and double-quoting, since
4254backslash has special meaning within double quotes.
4255Pattern substitution performs the check for unquoted <B>&amp;</B> after
4256expanding <I>string</I>;
4257shell programmers should quote any occurrences of <B>&amp;</B>
4258they want to be taken literally in the replacement
4259and ensure any instances of <B>&amp;</B> they want to be replaced are unquoted.
4260<P>
a0c0a00f
CR
4261If the
4262<B>nocasematch</B>
4263
4264shell option is enabled, the match is performed without regard to the case
4265of alphabetic characters.
17345e5a
JA
4266If
4267<I>parameter</I>
4268
4269is
4270<B>@</B>
4271
4272or
4273<B>*</B>,
4274
4275the substitution operation is applied to each positional
4276parameter in turn, and the expansion is the resultant list.
4277If
4278<I>parameter</I>
4279
4280is an array variable subscripted with
4281<B>@</B>
4282
4283or
4284<B>*</B>,
4285
4286the substitution operation is applied to each member of the
4287array in turn, and the expansion is the resultant list.
4288<DT>${<I>parameter</I><B>^</B><I>pattern</I>}<DD>
4289
4290<DT>${<I>parameter</I><B>^^</B><I>pattern</I>}<DD>
4291<DT>${<I>parameter</I><B>,</B><I>pattern</I>}<DD>
4292<DT>${<I>parameter</I><B>,,</B><I>pattern</I>}<DD>
4293
495aee44 4294<B>Case modification</B>.
17345e5a
JA
4295This expansion modifies the case of alphabetic characters in <I>parameter</I>.
4296The <I>pattern</I> is expanded to produce a pattern just as in
4297pathname expansion.
ac50fbac
CR
4298Each character in the expanded value of <I>parameter</I> is tested against
4299<I>pattern</I>, and, if it matches the pattern, its case is converted.
4300The pattern should not attempt to match more than one character.
17345e5a
JA
4301The <B>^</B> operator converts lowercase letters matching <I>pattern</I>
4302to uppercase; the <B>,</B> operator converts matching uppercase letters
4303to lowercase.
4304The <B>^^</B> and <B>,,</B> expansions convert each matched character in the
4305expanded value; the <B>^</B> and <B>,</B> expansions match and convert only
495aee44 4306the first character in the expanded value.
17345e5a
JA
4307If <I>pattern</I> is omitted, it is treated like a <B>?</B>, which matches
4308every character.
4309If
4310<I>parameter</I>
4311
4312is
4313<B>@</B>
4314
4315or
4316<B>*</B>,
4317
4318the case modification operation is applied to each positional
4319parameter in turn, and the expansion is the resultant list.
4320If
4321<I>parameter</I>
4322
4323is an array variable subscripted with
4324<B>@</B>
4325
4326or
4327<B>*</B>,
4328
4329the case modification operation is applied to each member of the
4330array in turn, and the expansion is the resultant list.
a0c0a00f
CR
4331<DT>${<I>parameter</I><B>@</B><I>operator</I>}<DD>
4332<B>Parameter transformation</B>.
4333The expansion is either a transformation of the value of <I>parameter</I>
4334or information about <I>parameter</I> itself, depending on the value of
4335<I>operator</I>. Each <I>operator</I> is a single letter:
4336<P>
4337<DL COMPACT><DT><DD>
4338
4339<DL COMPACT>
8868edaf
CR
4340<DT><B>U</B>
4341
4342<DD>
4343The expansion is a string that is the value of <I>parameter</I> with lowercase
4344alphabetic characters converted to uppercase.
4345<DT><B>u</B>
4346
4347<DD>
4348The expansion is a string that is the value of <I>parameter</I> with the first
4349character converted to uppercase, if it is alphabetic.
4350<DT><B>L</B>
4351
4352<DD>
4353The expansion is a string that is the value of <I>parameter</I> with uppercase
4354alphabetic characters converted to lowercase.
a0c0a00f
CR
4355<DT><B>Q</B>
4356
4357<DD>
4358The expansion is a string that is the value of <I>parameter</I> quoted in a
4359format that can be reused as input.
4360<DT><B>E</B>
4361
4362<DD>
4363The expansion is a string that is the value of <I>parameter</I> with backslash
74091dd4 4364escape sequences expanded as with the <B>$aq...aq</B> quoting mechanism.
a0c0a00f
CR
4365<DT><B>P</B>
4366
4367<DD>
4368The expansion is a string that is the result of expanding the value of
4369<I>parameter</I> as if it were a prompt string (see <B>PROMPTING</B> below).
4370<DT><B>A</B>
4371
4372<DD>
4373The expansion is a string in the form of
4374an assignment statement or <B>declare</B> command that, if
4375evaluated, will recreate <I>parameter</I> with its attributes and value.
8868edaf
CR
4376<DT><B>K</B>
4377
4378<DD>
4379Produces a possibly-quoted version of the value of <I>parameter</I>,
4380except that it prints the values of
4381indexed and associative arrays as a sequence of quoted key-value pairs
4382(see <B>Arrays</B> above).
a0c0a00f
CR
4383<DT><B>a</B>
4384
4385<DD>
4386The expansion is a string consisting of flag values representing
4387<I>parameter</I>'s attributes.
74091dd4
CR
4388<DT><B>k</B>
4389
4390<DD>
4391Like the K transformation, but expands the keys and values of
4392indexed and associative arrays to separate words after word splitting.
a0c0a00f
CR
4393
4394</DL>
4395<P>
4396
4397If
4398<I>parameter</I>
4399
4400is
4401<B>@</B>
4402
4403or
4404<B>*</B>,
4405
4406the operation is applied to each positional
4407parameter in turn, and the expansion is the resultant list.
4408If
4409<I>parameter</I>
4410
4411is an array variable subscripted with
4412<B>@</B>
4413
4414or
4415<B>*</B>,
4416
d233b485 4417the operation is applied to each member of the
a0c0a00f
CR
4418array in turn, and the expansion is the resultant list.
4419<P>
4420The result of the expansion is subject to word splitting and pathname
4421expansion as described below.
4422</DL>
4423
17345e5a
JA
4424</DL>
4425<A NAME="lbBC">&nbsp;</A>
4426<H4>Command Substitution</H4>
4427
17345e5a
JA
4428<I>Command substitution</I> allows the output of a command to replace
4429the command name. There are two forms:
17345e5a
JA
4430<DL COMPACT><DT><DD>
4431<P>
4432
4433<B>$(</B><I>command</I><B>)</B>
4434</DL>
4435
4436or
4437<DL COMPACT><DT><DD>
4438<B>`</B><I>command</I><B>`</B>
4439</DL>
4440
4441<P>
4442
4443<B>Bash</B>
4444
a0c0a00f
CR
4445performs the expansion by executing <I>command</I> in a subshell environment
4446and replacing the command substitution with the standard output of the
17345e5a
JA
4447command, with any trailing newlines deleted.
4448Embedded newlines are not deleted, but they may be removed during
4449word splitting.
4450The command substitution <B>$(cat </B><I>file</I>) can be replaced by
4451the equivalent but faster <B>$(&lt; </B><I>file</I>).
4452<P>
4453
4454When the old-style backquote form of substitution is used,
4455backslash retains its literal meaning except when followed by
4456<B>$</B>,
4457
4458<B>`</B>,
4459
4460or
4461<B>\</B>.
4462
4463The first backquote not preceded by a backslash terminates the
4464command substitution.
4465When using the $(<I>command</I>) form, all characters between the
4466parentheses make up the command; none are treated specially.
4467<P>
4468
4469Command substitutions may be nested. To nest when using the backquoted form,
4470escape the inner backquotes with backslashes.
4471<P>
4472
4473If the substitution appears within double quotes, word splitting and
4474pathname expansion are not performed on the results.
4475<A NAME="lbBD">&nbsp;</A>
4476<H4>Arithmetic Expansion</H4>
4477
17345e5a
JA
4478Arithmetic expansion allows the evaluation of an arithmetic expression
4479and the substitution of the result. The format for arithmetic expansion is:
4480<DL COMPACT><DT><DD>
4481<P>
4482
4483<B>$((</B><I>expression</I><B>))</B>
4484</DL>
4485
4486<P>
4487
4488The
4489<I>expression</I>
4490
74091dd4
CR
4491undergoes the same expansions
4492as if it were within double quotes,
4493but double quote characters in <I>expression</I> are not treated specially
4494and are removed.
ac50fbac
CR
4495All tokens in the expression undergo parameter and variable expansion,
4496command substitution, and quote removal.
4497The result is treated as the arithmetic expression to be evaluated.
17345e5a
JA
4498Arithmetic expansions may be nested.
4499<P>
4500
4501The evaluation is performed according to the rules listed below under
4502<FONT SIZE=-1><B>ARITHMETIC EVALUATION</B>.
4503
4504</FONT>
4505If
4506<I>expression</I>
4507
4508is invalid,
4509<B>bash</B>
4510
4511prints a message indicating failure and no substitution occurs.
4512<A NAME="lbBE">&nbsp;</A>
4513<H4>Process Substitution</H4>
4514
a0c0a00f
CR
4515<I>Process substitution</I> allows a process's input or output to be
4516referred to using a filename.
17345e5a
JA
4517It takes the form of
4518<B>&lt;(</B><I>list</I><B>)</B>
4519or
4520<B>&gt;(</B><I>list</I><B>)</B>.
a0c0a00f
CR
4521The process <I>list</I> is run asynchronously, and its input or output
4522appears as a filename.
4523This filename is
17345e5a 4524passed as an argument to the current command as the result of the
a0c0a00f
CR
4525expansion.
4526If the <B>&gt;(</B><I>list</I><B>)</B> form is used, writing to
17345e5a
JA
4527the file will provide input for <I>list</I>. If the
4528<B>&lt;(</B><I>list</I><B>)</B> form is used, the file passed as an
4529argument should be read to obtain the output of <I>list</I>.
a0c0a00f
CR
4530Process substitution is supported on systems that support named
4531pipes (<I>FIFOs</I>) or the <B>/dev/fd</B> method of naming open files.
17345e5a
JA
4532<P>
4533
4534When available, process substitution is performed
a0c0a00f 4535simultaneously with parameter and variable expansion,
17345e5a
JA
4536command substitution,
4537and arithmetic expansion.
4538<A NAME="lbBF">&nbsp;</A>
4539<H4>Word Splitting</H4>
4540
17345e5a
JA
4541The shell scans the results of
4542parameter expansion,
4543command substitution,
4544and
4545arithmetic expansion
4546that did not occur within double quotes for
4547<I>word splitting</I>.
4548
4549<P>
4550
4551The shell treats each character of
4552<FONT SIZE=-1><B>IFS</B>
4553
4554</FONT>
4555as a delimiter, and splits the results of the other
ac50fbac
CR
4556expansions into words using these characters as field terminators.
4557If
17345e5a
JA
4558<FONT SIZE=-1><B>IFS</B>
4559
4560</FONT>
4561is unset, or its
4562value is exactly
4563<B>&lt;space&gt;&lt;tab&gt;&lt;newline&gt;</B>,
4564
4565the default, then
4566sequences of
4567<B>&lt;space&gt;</B>,
4568
4569<B>&lt;tab&gt;</B>,
4570
4571and
4572<B>&lt;newline&gt;</B>
4573
4574at the beginning and end of the results of the previous
4575expansions are ignored, and
4576any sequence of
4577<FONT SIZE=-1><B>IFS</B>
4578
4579</FONT>
4580characters not at the beginning or end serves to delimit words.
4581If
4582<FONT SIZE=-1><B>IFS</B>
4583
4584</FONT>
4585has a value other than the default, then sequences of
4586the whitespace characters
a0c0a00f
CR
4587<B>space</B>,
4588
4589<B>tab</B>,
17345e5a
JA
4590
4591and
a0c0a00f 4592<B>newline</B>
17345e5a
JA
4593
4594are ignored at the beginning and end of the
4595word, as long as the whitespace character is in the
4596value of
4597<FONT SIZE=-1><B>IFS</B>
4598
4599</FONT>
4600(an
4601<FONT SIZE=-1><B>IFS</B>
4602
4603</FONT>
4604whitespace character).
4605Any character in
4606<FONT SIZE=-1><B>IFS</B>
4607
4608</FONT>
4609that is not
4610<FONT SIZE=-1><B>IFS</B>
4611
4612</FONT>
4613whitespace, along with any adjacent
4614<FONT SIZE=-1><B>IFS</B>
4615
4616</FONT>
4617whitespace characters, delimits a field.
4618A sequence of
4619<FONT SIZE=-1><B>IFS</B>
4620
4621</FONT>
4622whitespace characters is also treated as a delimiter.
4623If the value of
4624<FONT SIZE=-1><B>IFS</B>
4625
4626</FONT>
4627is null, no word splitting occurs.
4628<P>
4629
a0c0a00f
CR
4630Explicit null arguments (<B>&quot;&quot;</B> or <B>aqaq</B>) are retained
4631and passed to commands as empty strings.
17345e5a
JA
4632Unquoted implicit null arguments, resulting from the expansion of
4633parameters that have no values, are removed.
4634If a parameter with no value is expanded within double quotes, a
a0c0a00f
CR
4635null argument results and is retained
4636and passed to a command as an empty string.
4637When a quoted null argument appears as part of a word whose expansion is
4638non-null, the null argument is removed.
4639That is, the word
4640<TT>-daqaq</TT> becomes <TT>-d</TT> after word splitting and
4641null argument removal.
17345e5a
JA
4642<P>
4643
4644Note that if no expansion occurs, no splitting
4645is performed.
4646<A NAME="lbBG">&nbsp;</A>
4647<H4>Pathname Expansion</H4>
4648
17345e5a
JA
4649After word splitting,
4650unless the
4651<B>-f</B>
4652
4653option has been set,
4654<B>bash</B>
4655
4656scans each word for the characters
4657<B>*</B>,
4658
4659<B>?</B>,
4660
4661and
4662<B>[</B>.
4663
8868edaf 4664If one of these characters appears, and is not quoted, then the word is
17345e5a
JA
4665regarded as a
4666<I>pattern</I>,
4667
4668and replaced with an alphabetically sorted list of
ac50fbac
CR
4669filenames matching the pattern
4670(see
4671<FONT SIZE=-1><B>Pattern Matching</B>
4672
4673</FONT>
4674below).
4675If no matching filenames are found,
17345e5a
JA
4676and the shell option
4677<B>nullglob</B>
4678
4679is not enabled, the word is left unchanged.
a0c0a00f 4680If the
17345e5a
JA
4681<B>nullglob</B>
4682
4683option is set, and no matches are found,
4684the word is removed.
4685If the
4686<B>failglob</B>
4687
4688shell option is set, and no matches are found, an error message
4689is printed and the command is not executed.
4690If the shell option
4691<B>nocaseglob</B>
4692
4693is enabled, the match is performed without regard to the case
4694of alphabetic characters.
4695When a pattern is used for pathname expansion,
4696the character
4697<B>``.''</B>
4698
4699at the start of a name or immediately following a slash
4700must be matched explicitly, unless the shell option
4701<B>dotglob</B>
4702
4703is set.
74091dd4 4704In order to match the filenames
d233b485
CR
4705<B>``.''</B>
4706
4707and
74091dd4 4708<B>``..''</B>,
d233b485 4709
74091dd4
CR
4710the pattern must begin with ``.'' (for example, ``.?''),
4711even if
d233b485
CR
4712<B>dotglob</B>
4713
4714is set.
74091dd4
CR
4715If the
4716<B>globskipdots</B>
4717
4718shell option is enabled, the filenames
4719<B>``.''</B>
4720
4721and
4722<B>``..''</B>
4723
4724are never matched, even if the pattern begins with a
4725<B>``.''</B>.
4726
4727When not matching pathnames, the
17345e5a
JA
4728<B>``.''</B>
4729
4730character is not treated specially.
d233b485
CR
4731When matching a pathname, the slash character must always be
4732matched explicitly by a slash in the pattern, but in other matching
4733contexts it can be matched by a special pattern character as described
4734below under
4735<FONT SIZE=-1><B>Pattern Matching</B>.
4736
4737</FONT>
17345e5a
JA
4738See the description of
4739<B>shopt</B>
4740
4741below under
4742<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
4743
4744</FONT>
4745for a description of the
4746<B>nocaseglob</B>,
4747
4748<B>nullglob</B>,
4749
74091dd4
CR
4750<B>globskipdots</B>,
4751
17345e5a
JA
4752<B>failglob</B>,
4753
4754and
4755<B>dotglob</B>
4756
4757shell options.
4758<P>
4759
4760The
4761<FONT SIZE=-1><B>GLOBIGNORE</B>
4762
4763</FONT>
d233b485 4764shell variable may be used to restrict the set of file names matching a
17345e5a
JA
4765<I>pattern</I>.
4766
4767If
4768<FONT SIZE=-1><B>GLOBIGNORE</B>
4769
4770</FONT>
d233b485 4771is set, each matching file name that also matches one of the patterns in
17345e5a
JA
4772<FONT SIZE=-1><B>GLOBIGNORE</B>
4773
4774</FONT>
4775is removed from the list of matches.
a0c0a00f
CR
4776If the <B>nocaseglob</B> option is set, the matching against the patterns in
4777<FONT SIZE=-1><B>GLOBIGNORE</B>
4778
4779</FONT>
4780is performed without regard to case.
ac50fbac 4781The filenames
17345e5a
JA
4782<B>``.''</B>
4783
4784and
4785<B>``..''</B>
4786
4787are always ignored when
4788<FONT SIZE=-1><B>GLOBIGNORE</B>
4789
4790</FONT>
4791is set and not null. However, setting
4792<FONT SIZE=-1><B>GLOBIGNORE</B>
4793
4794</FONT>
4795to a non-null value has the effect of enabling the
4796<B>dotglob</B>
4797
ac50fbac 4798shell option, so all other filenames beginning with a
17345e5a
JA
4799<B>``.''</B>
4800
4801will match.
ac50fbac 4802To get the old behavior of ignoring filenames beginning with a
17345e5a
JA
4803<B>``.''</B>,
4804
4805make
4806<B>``.*''</B>
4807
4808one of the patterns in
4809<FONT SIZE=-1><B>GLOBIGNORE</B>.
4810
4811</FONT>
4812The
4813<B>dotglob</B>
4814
4815option is disabled when
4816<FONT SIZE=-1><B>GLOBIGNORE</B>
4817
4818</FONT>
4819is unset.
a0c0a00f
CR
4820The pattern matching honors the setting of the <B>extglob</B> shell
4821option.
17345e5a
JA
4822<P>
4823
4824<B>Pattern Matching</B>
4825<P>
4826
4827Any character that appears in a pattern, other than the special pattern
4828characters described below, matches itself. The NUL character may not
4829occur in a pattern. A backslash escapes the following character; the
4830escaping backslash is discarded when matching.
4831The special pattern characters must be quoted if
4832they are to be matched literally.
4833<P>
4834
4835The special pattern characters have the following meanings:
4836<P>
4837
4838
495aee44 4839<DL COMPACT><DT><DD>
17345e5a
JA
4840<DL COMPACT>
4841<DT><B>*</B>
4842
4843<DD>
4844Matches any string, including the null string.
4845When the <B>globstar</B> shell option is enabled, and <B>*</B> is used in
0001803f 4846a pathname expansion context, two adjacent <B>*</B>s used as a single
17345e5a
JA
4847pattern will match all files and zero or more directories and
4848subdirectories.
4849If followed by a <B>/</B>, two adjacent <B>*</B>s will match only directories
4850and subdirectories.
4851<DT><B>?</B>
4852
4853<DD>
4854Matches any single character.
4855<DT><B>[...]</B>
4856
4857<DD>
4858Matches any one of the enclosed characters. A pair of characters
4859separated by a hyphen denotes a
4860<I>range expression</I>;
ac50fbac 4861any character that falls between those two characters, inclusive,
17345e5a
JA
4862using the current locale's collating sequence and character set,
4863is matched. If the first character following the
4864<B>[</B>
4865
4866is a
4867<B>!</B>
4868
4869or a
4870<B>^</B>
4871
4872then any character not enclosed is matched.
74091dd4
CR
4873The sorting order of characters in range expressions,
4874and the characters included in the range,
4875are determined by
ac50fbac 4876the current locale and the values of the
0001803f
CR
4877<FONT SIZE=-1><B>LC_COLLATE</B>
4878
4879</FONT>
ac50fbac
CR
4880or
4881<FONT SIZE=-1><B>LC_ALL</B>
4882
4883</FONT>
4884shell variables, if set.
4885To obtain the traditional interpretation of range expressions, where
4886<B>[a-d]</B>
4887
4888is equivalent to
4889<B>[abcd]</B>,
4890
4891set value of the
4892<B>LC_ALL</B>
4893
4894shell variable to
4895<B>C</B>,
4896
4897or enable the
4898<B>globasciiranges</B>
4899
4900shell option.
a0c0a00f 4901A
17345e5a
JA
4902<B>-</B>
4903
4904may be matched by including it as the first or last character
4905in the set.
4906A
4907<B>]</B>
4908
4909may be matched by including it as the first character
4910in the set.
4911<BR>
4912
4913<P>
4914
4915
4916Within
4917<B>[</B>
4918
4919and
4920<B>]</B>,
4921
4922<I>character classes</I> can be specified using the syntax
4923<B>[:</B><I>class</I><B>:]</B>, where <I>class</I> is one of the
4924following classes defined in the POSIX standard:
4925</DL>
4926<P>
4927
4928<DL COMPACT><DT><DD>
4929<B>
4930</B>
4931
4932alnum alpha ascii blank cntrl digit graph lower print punct space upper word xdigit
4933<BR>
4934
4935A character class matches any character belonging to that class.
4936The <B>word</B> character class matches letters, digits, and the character _.
4937<BR>
4938
4939<P>
4940
4941
4942Within
4943<B>[</B>
4944
a0c0a00f 4945and
17345e5a
JA
4946<B>]</B>,
4947
4948an <I>equivalence class</I> can be specified using the syntax
4949<B>[=</B><I>c</I><B>=]</B>, which matches all characters with the
4950same collation weight (as defined by the current locale) as
4951the character <I>c</I>.
4952<BR>
4953
4954<P>
4955
4956
4957Within
4958<B>[</B>
4959
a0c0a00f 4960and
17345e5a
JA
4961<B>]</B>,
4962
4963the syntax <B>[.</B><I>symbol</I><B>.]</B> matches the collating symbol
4964<I>symbol</I>.
4965</DL>
4966
495aee44
CR
4967</DL>
4968
17345e5a
JA
4969
4970<P>
4971
4972If the <B>extglob</B> shell option is enabled using the <B>shopt</B>
74091dd4 4973builtin, the shell recognizes several extended pattern matching operators.
17345e5a
JA
4974In the following description, a <I>pattern-list</I> is a list of one
4975or more patterns separated by a <B>|</B>.
4976Composite patterns may be formed using one or more of the following
4977sub-patterns:
4978<P>
4979
4980<DL COMPACT><DT><DD>
4981<DL COMPACT>
4982<DT><B>?(</B><I>pattern-list</I><B>)</B><DD>
4983Matches zero or one occurrence of the given patterns
4984<DT><B>*(</B><I>pattern-list</I><B>)</B><DD>
4985Matches zero or more occurrences of the given patterns
4986<DT><B>+(</B><I>pattern-list</I><B>)</B><DD>
4987Matches one or more occurrences of the given patterns
4988<DT><B>@(</B><I>pattern-list</I><B>)</B><DD>
4989Matches one of the given patterns
4990<DT><B>!(</B><I>pattern-list</I><B>)</B><DD>
4991Matches anything except one of the given patterns
4992</DL></DL>
4993
4994
d233b485
CR
4995<P>
4996
74091dd4
CR
4997The<B>extglob</B> option changes the behavior of the parser, since the
4998parentheses are normally treated as operators with syntactic meaning.
4999To ensure that extended matching patterns are parsed correctly, make sure
5000that <B>extglob</B> is enabled before parsing constructs containing the
5001patterns, including shell functions and command substitutions.
5002<P>
5003
5004When matching filenames, the <B>dotglob</B> shell option determines
5005the set of filenames that are tested:
5006when <B>dotglob</B> is enabled, the set of filenames includes all files
5007beginning with ``.'', but ``.'' and ``..'' must be matched by a
5008pattern or sub-pattern that begins with a dot;
5009when it is disabled, the set does not
5010include any filenames beginning with ``.'' unless the pattern
5011or sub-pattern begins with a ``.''.
5012As above, ``.'' only has a special meaning when matching filenames.
5013<P>
5014
d233b485
CR
5015Complicated extended pattern matching against long strings is slow,
5016especially when the patterns contain alternations and the strings
5017contain multiple matches.
5018Using separate matches against shorter strings, or using arrays of
5019strings instead of a single long string, may be faster.
17345e5a
JA
5020<A NAME="lbBH">&nbsp;</A>
5021<H4>Quote Removal</H4>
5022
17345e5a
JA
5023After the preceding expansions, all unquoted occurrences of the
5024characters
5025<B>\</B>,
5026
5027<B>aq</B>,
5028
5029and <B>&quot;</B> that did not result from one of the above
5030expansions are removed.
5031<A NAME="lbBI">&nbsp;</A>
5032<H3>REDIRECTION</H3>
5033
5034Before a command is executed, its input and output
5035may be
5036<I>redirected</I>
5037
5038using a special notation interpreted by the shell.
74091dd4 5039<I>Redirection</I> allows commands' file handles to be
ac50fbac
CR
5040duplicated, opened, closed,
5041made to refer to different files,
5042and can change the files the command reads from and writes to.
5043Redirection may also be used to modify file handles in the
5044current shell execution environment.
5045The following redirection
17345e5a
JA
5046operators may precede or appear anywhere within a
5047<I>simple command</I>
5048
5049or may follow a
5050<I>command</I>.
5051
5052Redirections are processed in the order they appear, from
5053left to right.
5054<P>
5055
0001803f
CR
5056Each redirection that may be preceded by a file descriptor number
5057may instead be preceded by a word of the form {<I>varname</I>}.
5058In this case, for each redirection operator except
5059&gt;&amp;- and &lt;&amp;-, the shell will allocate a file descriptor greater
ac50fbac
CR
5060than or equal to 10 and assign it to <I>varname</I>.
5061If &gt;&amp;- or &lt;&amp;- is preceded
0001803f
CR
5062by {<I>varname</I>}, the value of <I>varname</I> defines the file
5063descriptor to close.
d233b485
CR
5064If {<I>varname</I>} is supplied, the redirection persists beyond
5065the scope of the command, allowing the shell programmer to manage
74091dd4
CR
5066the file descriptor's lifetime manually.
5067The <B>varredir_close</B> shell option manages this behavior.
0001803f
CR
5068<P>
5069
17345e5a
JA
5070In the following descriptions, if the file descriptor number is
5071omitted, and the first character of the redirection operator is
5072<B>&lt;</B>,
5073
5074the redirection refers to the standard input (file descriptor
50750). If the first character of the redirection operator is
5076<B>&gt;</B>,
5077
5078the redirection refers to the standard output (file descriptor
50791).
5080<P>
5081
5082The word following the redirection operator in the following
ac50fbac
CR
5083descriptions, unless otherwise noted, is subjected to
5084brace expansion, tilde expansion, parameter and variable expansion,
5085command substitution, arithmetic expansion, quote removal,
5086pathname expansion, and word splitting.
17345e5a
JA
5087If it expands to more than one word,
5088<B>bash</B>
5089
5090reports an error.
5091<P>
5092
a0c0a00f 5093Note that the order of redirections is significant. For example,
17345e5a
JA
5094the command
5095<DL COMPACT><DT><DD>
5096<P>
5097
5098ls <B>&gt;</B> dirlist 2<B>&gt;&amp;</B>1
5099</DL>
5100
5101<P>
5102
a0c0a00f 5103directs both standard output and standard error to the file
17345e5a
JA
5104<I>dirlist</I>,
5105
5106while the command
5107<DL COMPACT><DT><DD>
5108<P>
5109
5110ls 2<B>&gt;&amp;</B>1 <B>&gt;</B> dirlist
5111</DL>
5112
5113<P>
5114
5115directs only the standard output to file
5116<I>dirlist</I>,
5117
0001803f 5118because the standard error was duplicated from the standard output
17345e5a
JA
5119before the standard output was redirected to
5120<I>dirlist</I>.
5121
5122<P>
5123
5124<B>Bash</B> handles several filenames specially when they are used in
a0c0a00f
CR
5125redirections, as described in the following table.
5126If the operating system on which <B>bash</B> is running provides these
5127special files, bash will use them; otherwise it will emulate them
5128internally with the behavior described below.
17345e5a
JA
5129<DL COMPACT><DT><DD>
5130<P>
5131
5132
5133<DL COMPACT>
5134<DT><B>/dev/fd/</B><I>fd</I>
5135
5136<DD>
5137If <I>fd</I> is a valid integer, file descriptor <I>fd</I> is duplicated.
5138<DT><B>/dev/stdin</B>
5139
5140<DD>
5141File descriptor 0 is duplicated.
5142<DT><B>/dev/stdout</B>
5143
5144<DD>
5145File descriptor 1 is duplicated.
5146<DT><B>/dev/stderr</B>
5147
5148<DD>
5149File descriptor 2 is duplicated.
5150<DT><B>/dev/tcp/</B><I>host</I>/<I>port</I>
5151
5152<DD>
5153If <I>host</I> is a valid hostname or Internet address, and <I>port</I>
5154is an integer port number or service name, <B>bash</B> attempts to open
ac50fbac 5155the corresponding TCP socket.
17345e5a
JA
5156<DT><B>/dev/udp/</B><I>host</I>/<I>port</I>
5157
5158<DD>
5159If <I>host</I> is a valid hostname or Internet address, and <I>port</I>
5160is an integer port number or service name, <B>bash</B> attempts to open
ac50fbac 5161the corresponding UDP socket.
17345e5a
JA
5162
5163</DL></DL>
5164
5165<P>
5166
5167A failure to open or create a file causes the redirection to fail.
5168<P>
5169
5170Redirections using file descriptors greater than 9 should be used with
5171care, as they may conflict with file descriptors the shell uses
5172internally.
5173<A NAME="lbBJ">&nbsp;</A>
5174<H4>Redirecting Input</H4>
5175
17345e5a
JA
5176Redirection of input causes the file whose name results from
5177the expansion of
5178<I>word</I>
5179
5180to be opened for reading on file descriptor
5181<I>n</I>,
5182
5183or the standard input (file descriptor 0) if
5184<I>n</I>
5185
5186is not specified.
5187<P>
5188
5189The general format for redirecting input is:
5190<DL COMPACT><DT><DD>
5191<P>
5192
5193[<I>n</I>]<B>&lt;</B><I>word</I>
5194</DL>
5195
5196<A NAME="lbBK">&nbsp;</A>
5197<H4>Redirecting Output</H4>
5198
17345e5a
JA
5199Redirection of output causes the file whose name results from
5200the expansion of
5201<I>word</I>
5202
5203to be opened for writing on file descriptor
5204<I>n</I>,
5205
5206or the standard output (file descriptor 1) if
5207<I>n</I>
5208
5209is not specified. If the file does not exist it is created;
5210if it does exist it is truncated to zero size.
5211<P>
5212
5213The general format for redirecting output is:
5214<DL COMPACT><DT><DD>
5215<P>
5216
5217[<I>n</I>]<B>&gt;</B><I>word</I>
5218</DL>
5219
5220<P>
5221
5222If the redirection operator is
5223<B>&gt;</B>,
5224
5225and the
5226<B>noclobber</B>
5227
5228option to the
5229<B>set</B>
5230
5231builtin has been enabled, the redirection will fail if the file
5232whose name results from the expansion of <I>word</I> exists and is
5233a regular file.
5234If the redirection operator is
5235<B>&gt;|</B>,
5236
5237or the redirection operator is
5238<B>&gt;</B>
5239
5240and the
5241<B>noclobber</B>
5242
5243option to the
5244<B>set</B>
5245
5246builtin command is not enabled, the redirection is attempted even
5247if the file named by <I>word</I> exists.
5248<A NAME="lbBL">&nbsp;</A>
5249<H4>Appending Redirected Output</H4>
5250
17345e5a
JA
5251Redirection of output in this fashion
5252causes the file whose name results from
5253the expansion of
5254<I>word</I>
5255
5256to be opened for appending on file descriptor
5257<I>n</I>,
5258
5259or the standard output (file descriptor 1) if
5260<I>n</I>
5261
5262is not specified. If the file does not exist it is created.
5263<P>
5264
5265The general format for appending output is:
5266<DL COMPACT><DT><DD>
5267<P>
5268
5269[<I>n</I>]<B>&gt;&gt;</B><I>word</I>
5270</DL>
5271
17345e5a
JA
5272<A NAME="lbBM">&nbsp;</A>
5273<H4>Redirecting Standard Output and Standard Error</H4>
5274
17345e5a
JA
5275This construct allows both the
5276standard output (file descriptor 1) and
5277the standard error output (file descriptor 2)
5278to be redirected to the file whose name is the
5279expansion of
5280<I>word</I>.
5281
5282<P>
5283
5284There are two formats for redirecting standard output and
5285standard error:
5286<DL COMPACT><DT><DD>
5287<P>
5288
5289<B>&amp;&gt;</B><I>word</I>
5290</DL>
5291
5292and
5293<DL COMPACT><DT><DD>
5294<B>&gt;&amp;</B><I>word</I>
5295</DL>
5296
5297<P>
5298
5299Of the two forms, the first is preferred.
5300This is semantically equivalent to
5301<DL COMPACT><DT><DD>
5302<P>
5303
5304<B>&gt;</B><I>word</I> 2<B>&gt;&amp;</B>1
5305</DL>
5306
5307<P>
5308
ac50fbac
CR
5309When using the second form, <I>word</I> may not expand to a number or
5310<B>-</B>. If it does, other redirection operators apply
5311(see <B>Duplicating File Descriptors</B> below) for compatibility
5312reasons.
17345e5a
JA
5313<A NAME="lbBN">&nbsp;</A>
5314<H4>Appending Standard Output and Standard Error</H4>
5315
17345e5a
JA
5316This construct allows both the
5317standard output (file descriptor 1) and
5318the standard error output (file descriptor 2)
5319to be appended to the file whose name is the
5320expansion of
5321<I>word</I>.
5322
5323<P>
5324
5325The format for appending standard output and standard error is:
5326<DL COMPACT><DT><DD>
5327<P>
5328
5329<B>&amp;&gt;&gt;</B><I>word</I>
5330</DL>
5331
5332<P>
5333
5334This is semantically equivalent to
5335<DL COMPACT><DT><DD>
5336<P>
5337
5338<B>&gt;&gt;</B><I>word</I> 2<B>&gt;&amp;</B>1
5339</DL>
5340
ac50fbac
CR
5341<P>
5342
5343(see <B>Duplicating File Descriptors</B> below).
17345e5a
JA
5344<A NAME="lbBO">&nbsp;</A>
5345<H4>Here Documents</H4>
5346
17345e5a
JA
5347This type of redirection instructs the shell to read input from the
5348current source until a line containing only
5349<I>delimiter</I>
5350
5351(with no trailing blanks)
5352is seen. All of
5353the lines read up to that point are then used as the standard
a0c0a00f 5354input (or file descriptor <I>n</I> if <I>n</I> is specified) for a command.
17345e5a
JA
5355<P>
5356
5357The format of here-documents is:
5358<DL COMPACT><DT><DD>
5359<P>
5360
5361<PRE>
a0c0a00f 5362[<I>n</I>]<B>&lt;&lt;</B>[<B>-</B>]<I>word</I>
17345e5a
JA
5363 <I>here-document</I>
5364<I>delimiter</I>
5365</PRE>
5366
5367</DL>
5368
5369<P>
5370
ac50fbac
CR
5371No parameter and variable expansion, command substitution,
5372arithmetic expansion, or pathname expansion is performed on
17345e5a
JA
5373<I>word</I>.
5374
a0c0a00f 5375If any part of
17345e5a
JA
5376<I>word</I>
5377
a0c0a00f 5378is quoted, the
17345e5a
JA
5379<I>delimiter</I>
5380
5381is the result of quote removal on
5382<I>word</I>,
5383
5384and the lines in the here-document are not expanded.
5385If <I>word</I> is unquoted,
ac50fbac
CR
5386all lines of the here-document are subjected to
5387parameter expansion, command substitution, and arithmetic expansion,
5388the character sequence
17345e5a
JA
5389<B>\&lt;newline&gt;</B>
5390
5391is ignored, and
5392<B>\</B>
5393
5394must be used to quote the characters
5395<B>\</B>,
5396
5397<B>$</B>,
5398
5399and
5400<B>`</B>.
5401
5402<P>
5403
5404If the redirection operator is
5405<B>&lt;&lt;-</B>,
5406
5407then all leading tab characters are stripped from input lines and the
5408line containing
5409<I>delimiter</I>.
5410
5411This allows
5412here-documents within shell scripts to be indented in a
5413natural fashion.
5414<A NAME="lbBP">&nbsp;</A>
5415<H4>Here Strings</H4>
5416
5417A variant of here documents, the format is:
5418<DL COMPACT><DT><DD>
5419<P>
5420
5421<PRE>
a0c0a00f 5422[<I>n</I>]<B>&lt;&lt;&lt;</B><I>word</I>
17345e5a
JA
5423</PRE>
5424
5425</DL>
5426
5427<P>
5428
ac50fbac 5429The <I>word</I> undergoes
d233b485 5430tilde expansion, parameter and variable expansion,
ac50fbac
CR
5431command substitution, arithmetic expansion, and quote removal.
5432Pathname expansion and word splitting are not performed.
a0c0a00f
CR
5433The result is supplied as a single string, with a newline appended,
5434to the command on its
5435standard input (or file descriptor <I>n</I> if <I>n</I> is specified).
17345e5a
JA
5436<A NAME="lbBQ">&nbsp;</A>
5437<H4>Duplicating File Descriptors</H4>
5438
17345e5a
JA
5439The redirection operator
5440<DL COMPACT><DT><DD>
5441<P>
5442
5443[<I>n</I>]<B>&lt;&amp;</B><I>word</I>
5444</DL>
5445
5446<P>
5447
5448is used to duplicate input file descriptors.
5449If
5450<I>word</I>
5451
5452expands to one or more digits, the file descriptor denoted by
5453<I>n</I>
5454
5455is made to be a copy of that file descriptor.
5456If the digits in
5457<I>word</I>
5458
5459do not specify a file descriptor open for input, a redirection error occurs.
5460If
5461<I>word</I>
5462
5463evaluates to
5464<B>-</B>,
5465
5466file descriptor
5467<I>n</I>
5468
5469is closed. If
5470<I>n</I>
5471
5472is not specified, the standard input (file descriptor 0) is used.
5473<P>
5474
5475The operator
5476<DL COMPACT><DT><DD>
5477<P>
5478
5479[<I>n</I>]<B>&gt;&amp;</B><I>word</I>
5480</DL>
5481
5482<P>
5483
5484is used similarly to duplicate output file descriptors. If
5485<I>n</I>
5486
5487is not specified, the standard output (file descriptor 1) is used.
5488If the digits in
5489<I>word</I>
5490
5491do not specify a file descriptor open for output, a redirection error occurs.
ac50fbac
CR
5492If
5493<I>word</I>
5494
5495evaluates to
5496<B>-</B>,
5497
5498file descriptor
5499<I>n</I>
5500
5501is closed.
17345e5a 5502As a special case, if <I>n</I> is omitted, and <I>word</I> does not
ac50fbac 5503expand to one or more digits or <B>-</B>, the standard output and standard
17345e5a
JA
5504error are redirected as described previously.
5505<A NAME="lbBR">&nbsp;</A>
5506<H4>Moving File Descriptors</H4>
5507
17345e5a
JA
5508The redirection operator
5509<DL COMPACT><DT><DD>
5510<P>
5511
5512[<I>n</I>]<B>&lt;&amp;</B><I>digit</I><B>-</B>
5513</DL>
5514
5515<P>
5516
5517moves the file descriptor <I>digit</I> to file descriptor
5518<I>n</I>,
5519
5520or the standard input (file descriptor 0) if <I>n</I> is not specified.
5521<I>digit</I> is closed after being duplicated to <I>n</I>.
5522<P>
5523
5524Similarly, the redirection operator
5525<DL COMPACT><DT><DD>
5526<P>
5527
5528[<I>n</I>]<B>&gt;&amp;</B><I>digit</I><B>-</B>
5529</DL>
5530
5531<P>
5532
5533moves the file descriptor <I>digit</I> to file descriptor
5534<I>n</I>,
5535
5536or the standard output (file descriptor 1) if <I>n</I> is not specified.
5537<A NAME="lbBS">&nbsp;</A>
5538<H4>Opening File Descriptors for Reading and Writing</H4>
5539
17345e5a
JA
5540The redirection operator
5541<DL COMPACT><DT><DD>
5542<P>
5543
5544[<I>n</I>]<B>&lt;&gt;</B><I>word</I>
5545</DL>
5546
5547<P>
5548
5549causes the file whose name is the expansion of
5550<I>word</I>
5551
5552to be opened for both reading and writing on file descriptor
5553<I>n</I>,
5554
5555or on file descriptor 0 if
5556<I>n</I>
5557
5558is not specified. If the file does not exist, it is created.
5559<A NAME="lbBT">&nbsp;</A>
5560<H3>ALIASES</H3>
5561
5562<I>Aliases</I> allow a string to be substituted for a word when it is used
5563as the first word of a simple command.
5564The shell maintains a list of aliases that may be set and unset with the
5565<B>alias</B>
5566
5567and
5568<B>unalias</B>
5569
5570builtin commands (see
5571<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
5572
5573</FONT>
5574below).
5575The first word of each simple command, if unquoted,
5576is checked to see if it has an
5577alias. If so, that word is replaced by the text of the alias.
5578The characters <B>/</B>, <B>$</B>, <B>`</B>, and <B>=</B> and
5579any of the shell <I>metacharacters</I> or quoting characters
5580listed above may not appear in an alias name.
5581The replacement text may contain any valid shell input,
5582including shell metacharacters.
5583The first word of the replacement text is tested
5584for aliases, but a word that is identical to an alias being expanded
5585is not expanded a second time.
5586This means that one may alias
5587<B>ls</B>
5588
5589to
5590<B>ls -F</B>,
5591
5592for instance, and
5593<B>bash</B>
5594
5595does not try to recursively expand the replacement text.
5596If the last character of the alias value is a
5597<I>blank</I>,
5598
5599then the next command
5600word following the alias is also checked for alias expansion.
5601<P>
5602
5603Aliases are created and listed with the
5604<B>alias</B>
5605
5606command, and removed with the
5607<B>unalias</B>
5608
5609command.
5610<P>
5611
5612There is no mechanism for using arguments in the replacement text.
74091dd4 5613If arguments are needed, use a shell function (see
17345e5a
JA
5614<FONT SIZE=-1><B>FUNCTIONS</B>
5615
5616</FONT>
5617below).
5618<P>
5619
5620Aliases are not expanded when the shell is not interactive, unless
5621the
5622<B>expand_aliases</B>
5623
5624shell option is set using
5625<B>shopt</B>
5626
5627(see the description of
5628<B>shopt</B>
5629
5630under
5631<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B></FONT>
5632below).
5633<P>
5634
5635The rules concerning the definition and use of aliases are
5636somewhat confusing.
5637<B>Bash</B>
5638
d233b485
CR
5639always reads at least one complete line of input,
5640and all lines that make up a compound command,
5641before executing any of the commands on that line or the compound command.
5642Aliases are expanded when a
17345e5a
JA
5643command is read, not when it is executed. Therefore, an
5644alias definition appearing on the same line as another
5645command does not take effect until the next line of input is read.
5646The commands following the alias definition
5647on that line are not affected by the new alias.
5648This behavior is also an issue when functions are executed.
5649Aliases are expanded when a function definition is read,
5650not when the function is executed, because a function definition
a0c0a00f 5651is itself a command. As a consequence, aliases
17345e5a
JA
5652defined in a function are not available until after that
5653function is executed. To be safe, always put
5654alias definitions on a separate line, and do not use
5655<B>alias</B>
5656
5657in compound commands.
5658<P>
5659
5660For almost every purpose, aliases are superseded by
5661shell functions.
5662<A NAME="lbBU">&nbsp;</A>
5663<H3>FUNCTIONS</H3>
5664
5665A shell function, defined as described above under
5666<FONT SIZE=-1><B>SHELL GRAMMAR</B>,
5667
5668</FONT>
5669stores a series of commands for later execution.
5670When the name of a shell function is used as a simple command name,
5671the list of commands associated with that function name is executed.
5672Functions are executed in the context of the
5673current shell; no new process is created to interpret
5674them (contrast this with the execution of a shell script).
5675When a function is executed, the arguments to the
5676function become the positional parameters
5677during its execution.
5678The special parameter
5679<B>#</B>
5680
495aee44 5681is updated to reflect the change. Special parameter <B>0</B>
17345e5a
JA
5682is unchanged.
5683The first element of the
5684<FONT SIZE=-1><B>FUNCNAME</B>
5685
5686</FONT>
5687variable is set to the name of the function while the function
5688is executing.
0001803f
CR
5689<P>
5690
17345e5a
JA
5691All other aspects of the shell execution
5692environment are identical between a function and its caller
a0c0a00f 5693with these exceptions: the
17345e5a
JA
5694<FONT SIZE=-1><B>DEBUG</B>
5695
5696</FONT>
5697and
5698<B>RETURN</B>
5699
5700traps (see the description of the
5701<B>trap</B>
5702
5703builtin under
5704<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
5705
5706</FONT>
5707below) are not inherited unless the function has been given the
5708<B>trace</B> attribute (see the description of the
5709<FONT SIZE=-1><B>declare</B>
5710
5711</FONT>
5712builtin below) or the
5713<B>-o functrace</B> shell option has been enabled with
5714the <B>set</B> builtin
0001803f
CR
5715(in which case all functions inherit the <B>DEBUG</B> and <B>RETURN</B> traps),
5716and the
5717<FONT SIZE=-1><B>ERR</B>
5718
5719</FONT>
5720trap is not inherited unless the <B>-o errtrace</B> shell option has
5721been enabled.
17345e5a
JA
5722<P>
5723
5724Variables local to the function may be declared with the
5725<B>local</B>
5726
74091dd4
CR
5727builtin command (<I>local variables</I>).
5728Ordinarily, variables and their values
17345e5a 5729are shared between the function and its caller.
d233b485
CR
5730If a variable is declared <B>local</B>, the variable's visible scope
5731is restricted to that function and its children (including the functions
5732it calls).
74091dd4
CR
5733<P>
5734
5735In the following description, the <I>current scope</I> is a currently-
5736executing function.
5737Previous scopes consist of that function's caller and so on,
5738back to the &quot;global&quot; scope, where the shell is not executing
5739any shell function.
5740Consequently, a local variable at the current scope is a variable
5741declared using the <B>local</B> or <B>declare</B> builtins in the
5742function that is currently executing.
5743<P>
5744
d233b485
CR
5745Local variables &quot;shadow&quot; variables with the same name declared at
5746previous scopes.
5747For instance, a local variable declared in a function
5748hides a global variable of the same name: references and assignments
5749refer to the local variable, leaving the global variable unmodified.
5750When the function returns, the global variable is once again visible.
5751<P>
5752
5753The shell uses <I>dynamic scoping</I> to control a variable's visibility
5754within functions.
5755With dynamic scoping, visible variables and their values
5756are a result of the sequence of function calls that caused execution
5757to reach the current function.
5758The value of a variable that a function sees depends
5759on its value within its caller, if any, whether that caller is
5760the &quot;global&quot; scope or another shell function.
5761This is also the value that a local variable
5762declaration &quot;shadows&quot;, and the value that is restored when the function
5763returns.
5764<P>
5765
5766For example, if a variable <I>var</I> is declared as local in function
5767<I>func1</I>, and <I>func1</I> calls another function <I>func2</I>,
5768references to <I>var</I> made from within <I>func2</I> will resolve to the
5769local variable <I>var</I> from <I>func1</I>, shadowing any global variable
5770named <I>var</I>.
5771<P>
5772
5773The <B>unset</B> builtin also acts using the same dynamic scope: if a
5774variable is local to the current scope, <B>unset</B> will unset it;
5775otherwise the unset will refer to the variable found in any calling scope
5776as described above.
5777If a variable at the current local scope is unset, it will remain so
74091dd4 5778(appearing as unset)
d233b485
CR
5779until it is reset in that scope or until the function returns.
5780Once the function returns, any instance of the variable at a previous
5781scope will become visible.
5782If the unset acts on a variable at a previous scope, any instance of a
74091dd4
CR
5783variable with that name that had been shadowed will become visible
5784(see below how the <B>localvar_unset</B> shell option changes this behavior).
17345e5a
JA
5785<P>
5786
495aee44
CR
5787The <B>FUNCNEST</B> variable, if set to a numeric value greater
5788than 0, defines a maximum function nesting level. Function
5789invocations that exceed the limit cause the entire command to
5790abort.
5791<P>
5792
17345e5a
JA
5793If the builtin command
5794<B>return</B>
5795
5796is executed in a function, the function completes and
5797execution resumes with the next command after the function
5798call.
5799Any command associated with the <B>RETURN</B> trap is executed
5800before execution resumes.
5801When a function completes, the values of the
5802positional parameters and the special parameter
5803<B>#</B>
5804
5805are restored to the values they had prior to the function's
5806execution.
5807<P>
5808
5809Function names and definitions may be listed with the
5810<B>-f</B>
5811
5812option to the
5813<B>declare</B>
5814
5815or
5816<B>typeset</B>
5817
5818builtin commands. The
5819<B>-F</B>
5820
5821option to
5822<B>declare</B>
5823
5824or
5825<B>typeset</B>
5826
5827will list the function names only
5828(and optionally the source file and line number, if the <B>extdebug</B>
5829shell option is enabled).
74091dd4
CR
5830Functions may be exported so that child shell processes
5831(those created when executing a separate shell invocation)
17345e5a
JA
5832automatically have them defined with the
5833<B>-f</B>
5834
8868edaf 5835option to the
17345e5a
JA
5836<B>export</B>
5837
5838builtin.
5839A function definition may be deleted using the <B>-f</B> option to
5840the
5841<B>unset</B>
5842
5843builtin.
17345e5a
JA
5844<P>
5845
495aee44
CR
5846Functions may be recursive.
5847The <B>FUNCNEST</B> variable may be used to limit the depth of the
5848function call stack and restrict the number of function invocations.
5849By default, no limit is imposed on the number of recursive calls.
17345e5a
JA
5850<A NAME="lbBV">&nbsp;</A>
5851<H3>ARITHMETIC EVALUATION</H3>
5852
5853The shell allows arithmetic expressions to be evaluated, under
5854certain circumstances (see the <B>let</B> and <B>declare</B> builtin
a0c0a00f 5855commands, the <B>((</B> compound command, and <B>Arithmetic Expansion</B>).
17345e5a
JA
5856Evaluation is done in fixed-width integers with no check for overflow,
5857though division by 0 is trapped and flagged as an error.
5858The operators and their precedence, associativity, and values
5859are the same as in the C language.
5860The following list of operators is grouped into levels of
5861equal-precedence operators.
5862The levels are listed in order of decreasing precedence.
5863<P>
5864
5865
5866<DL COMPACT>
5867<DT><B></B><I>id</I>++ <I>id</I>--
5868
5869<DD>
5870variable post-increment and post-decrement
17345e5a
JA
5871<DT><B>- +</B>
5872
5873<DD>
5874unary minus and plus
d233b485
CR
5875<DT><B>++</B><I>id</I> --<I>id</I>
5876
5877<DD>
5878variable pre-increment and pre-decrement
17345e5a
JA
5879<DT><B>! ~</B>
5880
5881<DD>
5882logical and bitwise negation
5883<DT><B>**</B>
5884
5885<DD>
5886exponentiation
5887<DT><B>* / %</B>
5888
5889<DD>
5890multiplication, division, remainder
5891<DT><B>+ -</B>
5892
5893<DD>
5894addition, subtraction
5895<DT><B>&lt;&lt; &gt;&gt;</B>
5896
5897<DD>
5898left and right bitwise shifts
5899<DT><B>&lt;= &gt;= &lt; &gt;</B>
5900
5901<DD>
5902comparison
5903<DT><B>== !=</B>
5904
5905<DD>
5906equality and inequality
5907<DT><B>&amp;</B>
5908
5909<DD>
5910bitwise AND
5911<DT><B>^</B>
5912
5913<DD>
5914bitwise exclusive OR
5915<DT><B>|</B>
5916
5917<DD>
5918bitwise OR
5919<DT><B>&amp;&amp;</B>
5920
5921<DD>
5922logical AND
5923<DT><B>||</B>
5924
5925<DD>
5926logical OR
5927<DT><B></B><I>expr</I>?<I>expr</I>:<I>expr</I>
5928
5929<DD>
5930conditional operator
5931<DT><B>= *= /= %= += -= &lt;&lt;= &gt;&gt;= &amp;= ^= |=</B>
5932
5933<DD>
5934assignment
5935<DT><B></B><I>expr1</I> , <I>expr2</I>
5936
5937<DD>
5938comma
5939
5940</DL>
5941<P>
5942
5943Shell variables are allowed as operands; parameter expansion is
5944performed before the expression is evaluated.
5945Within an expression, shell variables may also be referenced by name
5946without using the parameter expansion syntax.
5947A shell variable that is null or unset evaluates to 0 when referenced
5948by name without using the parameter expansion syntax.
5949The value of a variable is evaluated as an arithmetic expression
5950when it is referenced, or when a variable which has been given the
5951<I>integer</I> attribute using <B>declare -i</B> is assigned a value.
5952A null value evaluates to 0.
495aee44 5953A shell variable need not have its <I>integer</I> attribute
17345e5a
JA
5954turned on to be used in an expression.
5955<P>
5956
8868edaf
CR
5957Integer constants follow the C language definition, without suffixes or
5958character constants.
17345e5a
JA
5959Constants with a leading 0 are interpreted as octal numbers.
5960A leading 0x or 0X denotes hexadecimal.
495aee44 5961Otherwise, numbers take the form [<I>base#</I>]n, where the optional <I>base</I>
17345e5a
JA
5962is a decimal number between 2 and 64 representing the arithmetic
5963base, and <I>n</I> is a number in that base.
5964If <I>base#</I> is omitted, then base 10 is used.
ac50fbac 5965When specifying <I>n</I>,
8868edaf 5966if a non-digit is required,
a0c0a00f 5967the digits greater than 9 are represented by the lowercase letters,
17345e5a
JA
5968the uppercase letters, @, and _, in that order.
5969If <I>base</I> is less than or equal to 36, lowercase and uppercase
5970letters may be used interchangeably to represent numbers between 10
5971and 35.
5972<P>
5973
5974Operators are evaluated in order of precedence. Sub-expressions in
5975parentheses are evaluated first and may override the precedence
5976rules above.
5977<A NAME="lbBW">&nbsp;</A>
5978<H3>CONDITIONAL EXPRESSIONS</H3>
5979
5980Conditional expressions are used by the <B>[[</B> compound command and
5981the <B>test</B> and <B>[</B> builtin commands to test file attributes
5982and perform string and arithmetic comparisons.
8868edaf 5983The <B>test</B> and <B>[</B> commands determine their behavior based on
d233b485
CR
5984the number of arguments; see the descriptions of those commands for any
5985other command-specific actions.
5986<P>
5987
17345e5a 5988Expressions are formed from the following unary or binary primaries.
a0c0a00f
CR
5989<B>Bash</B> handles several filenames specially when they are used in
5990expressions.
5991If the operating system on which <B>bash</B> is running provides these
5992special files, bash will use them; otherwise it will emulate them
5993internally with this behavior:
17345e5a
JA
5994If any <I>file</I> argument to one of the primaries is of the form
5995<I>/dev/fd/n</I>, then file descriptor <I>n</I> is checked.
5996If the <I>file</I> argument to one of the primaries is one of
5997<I>/dev/stdin</I>, <I>/dev/stdout</I>, or <I>/dev/stderr</I>, file
5998descriptor 0, 1, or 2, respectively, is checked.
5999<P>
6000
6001Unless otherwise specified, primaries that operate on files follow symbolic
6002links and operate on the target of the link, rather than the link itself.
6003<P>
6004
0001803f 6005
495aee44 6006When used with <B>[[</B>, the <B>&lt;</B> and <B>&gt;</B> operators sort
0001803f 6007lexicographically using the current locale.
495aee44 6008The <B>test</B> command sorts using ASCII ordering.
0001803f
CR
6009<P>
6010
17345e5a
JA
6011<DL COMPACT>
6012<DT><B>-a </B><I>file</I>
6013
6014<DD>
6015True if <I>file</I> exists.
6016<DT><B>-b </B><I>file</I>
6017
6018<DD>
6019True if <I>file</I> exists and is a block special file.
6020<DT><B>-c </B><I>file</I>
6021
6022<DD>
6023True if <I>file</I> exists and is a character special file.
6024<DT><B>-d </B><I>file</I>
6025
6026<DD>
6027True if <I>file</I> exists and is a directory.
6028<DT><B>-e </B><I>file</I>
6029
6030<DD>
6031True if <I>file</I> exists.
6032<DT><B>-f </B><I>file</I>
6033
6034<DD>
6035True if <I>file</I> exists and is a regular file.
6036<DT><B>-g </B><I>file</I>
6037
6038<DD>
6039True if <I>file</I> exists and is set-group-id.
6040<DT><B>-h </B><I>file</I>
6041
6042<DD>
6043True if <I>file</I> exists and is a symbolic link.
6044<DT><B>-k </B><I>file</I>
6045
6046<DD>
6047True if <I>file</I> exists and its ``sticky'' bit is set.
6048<DT><B>-p </B><I>file</I>
6049
6050<DD>
6051True if <I>file</I> exists and is a named pipe (FIFO).
6052<DT><B>-r </B><I>file</I>
6053
6054<DD>
6055True if <I>file</I> exists and is readable.
6056<DT><B>-s </B><I>file</I>
6057
6058<DD>
6059True if <I>file</I> exists and has a size greater than zero.
6060<DT><B>-t </B><I>fd</I>
6061
6062<DD>
6063True if file descriptor
6064<I>fd</I>
6065
6066is open and refers to a terminal.
6067<DT><B>-u </B><I>file</I>
6068
6069<DD>
6070True if <I>file</I> exists and its set-user-id bit is set.
6071<DT><B>-w </B><I>file</I>
6072
6073<DD>
6074True if <I>file</I> exists and is writable.
6075<DT><B>-x </B><I>file</I>
6076
6077<DD>
6078True if <I>file</I> exists and is executable.
17345e5a
JA
6079<DT><B>-G </B><I>file</I>
6080
6081<DD>
6082True if <I>file</I> exists and is owned by the effective group id.
6083<DT><B>-L </B><I>file</I>
6084
6085<DD>
6086True if <I>file</I> exists and is a symbolic link.
17345e5a
JA
6087<DT><B>-N </B><I>file</I>
6088
6089<DD>
6090True if <I>file</I> exists and has been modified since it was last read.
495aee44
CR
6091<DT><B>-O </B><I>file</I>
6092
6093<DD>
6094True if <I>file</I> exists and is owned by the effective user id.
6095<DT><B>-S </B><I>file</I>
6096
6097<DD>
6098True if <I>file</I> exists and is a socket.
6099<DT><I>file1</I> <B>-ef</B> <I>file2</I><DD>
6100True if <I>file1</I> and <I>file2</I> refer to the same device and
6101inode numbers.
17345e5a
JA
6102<DT><I>file1</I> -<B>nt</B> <I>file2</I><DD>
6103True if <I>file1</I> is newer (according to modification date) than <I>file2</I>,
6104or if <I>file1</I> exists and file2 does not.
6105<DT><I>file1</I> -<B>ot</B> <I>file2</I><DD>
6106True if <I>file1</I> is older than <I>file2</I>, or if <I>file2</I> exists
6107and <I>file1</I> does not.
17345e5a
JA
6108<DT><B>-o </B><I>optname</I>
6109
6110<DD>
495aee44 6111True if the shell option
17345e5a
JA
6112<I>optname</I>
6113
6114is enabled.
6115See the list of options under the description of the
6116<B>-o</B>
6117
6118option to the
6119<B>set</B>
6120
6121builtin below.
495aee44
CR
6122<DT><B>-v </B><I>varname</I>
6123
6124<DD>
6125True if the shell variable
6126<I>varname</I>
6127
6128is set (has been assigned a value).
ac50fbac
CR
6129<DT><B>-R </B><I>varname</I>
6130
6131<DD>
6132True if the shell variable
6133<I>varname</I>
6134
6135is set and is a name reference.
17345e5a
JA
6136<DT><B>-z </B><I>string</I>
6137
6138<DD>
6139True if the length of <I>string</I> is zero.
6140<DT><I>string</I><DD>
6141
6142<DT><B>-n </B><I>string</I>
6143
6144<DD>
6145
6146True if the length of
6147<I>string</I>
6148
6149is non-zero.
6150<DT><I>string1</I> <B>==</B> <I>string2</I><DD>
0001803f
CR
6151
6152<DT><I>string1</I> <B>=</B> <I>string2</I><DD>
6153
6154True if the strings are equal. <B>=</B> should be used
6155with the <B>test</B> command for POSIX conformance.
ac50fbac
CR
6156When used with the <B>[[</B> command, this performs pattern matching as
6157described above (<B>Compound Commands</B>).
17345e5a
JA
6158<DT><I>string1</I> <B>!=</B> <I>string2</I><DD>
6159True if the strings are not equal.
6160<DT><I>string1</I> <B>&lt;</B> <I>string2</I><DD>
0001803f 6161True if <I>string1</I> sorts before <I>string2</I> lexicographically.
17345e5a 6162<DT><I>string1</I> <B>&gt;</B> <I>string2</I><DD>
0001803f 6163True if <I>string1</I> sorts after <I>string2</I> lexicographically.
17345e5a
JA
6164<DT><I>arg1</I> <B>OP</B> <I>arg2</I>
6165
6166<DD>
6167<FONT SIZE=-1><B>OP</B>
6168
6169</FONT>
6170is one of
6171<B>-eq</B>,
6172
6173<B>-ne</B>,
6174
6175<B>-lt</B>,
6176
6177<B>-le</B>,
6178
6179<B>-gt</B>,
6180
6181or
6182<B>-ge</B>.
6183
6184These arithmetic binary operators return true if <I>arg1</I>
6185is equal to, not equal to, less than, less than or equal to,
6186greater than, or greater than or equal to <I>arg2</I>, respectively.
6187<I>Arg1</I>
6188
6189and
6190<I>arg2</I>
6191
6192may be positive or negative integers.
d233b485
CR
6193When used with the <B>[[</B> command,
6194<I>Arg1</I>
6195
6196and
6197<I>Arg2</I>
6198
8868edaf 6199are evaluated as arithmetic expressions (see
d233b485
CR
6200<FONT SIZE=-1><B>ARITHMETIC EVALUATION</B>
6201
6202</FONT>
6203above).
17345e5a
JA
6204
6205</DL>
6206<A NAME="lbBX">&nbsp;</A>
6207<H3>SIMPLE COMMAND EXPANSION</H3>
6208
6209When a simple command is executed, the shell performs the following
8868edaf
CR
6210expansions, assignments, and redirections, from left to right, in
6211the following order.
17345e5a
JA
6212<DL COMPACT>
6213<DT>1.<DD>
6214The words that the parser has marked as variable assignments (those
6215preceding the command name) and redirections are saved for later
6216processing.
6217<DT>2.<DD>
6218The words that are not variable assignments or redirections are
6219expanded. If any words remain after expansion, the first word
6220is taken to be the name of the command and the remaining words are
6221the arguments.
6222<DT>3.<DD>
6223Redirections are performed as described above under
6224<FONT SIZE=-1><B>REDIRECTION</B>.
6225
6226</FONT>
6227<DT>4.<DD>
6228The text after the <B>=</B> in each variable assignment undergoes tilde
6229expansion, parameter expansion, command substitution, arithmetic expansion,
6230and quote removal before being assigned to the variable.
6231</DL>
6232<P>
6233
6234If no command name results, the variable assignments affect the current
74091dd4
CR
6235shell environment.
6236In the case of such a command (one that consists only of assignment
6237statements and redirections), assignment statements are performed before
6238redirections.
6239Otherwise, the variables are added to the environment
17345e5a
JA
6240of the executed command and do not affect the current shell environment.
6241If any of the assignments attempts to assign a value to a readonly variable,
6242an error occurs, and the command exits with a non-zero status.
6243<P>
6244
6245If no command name results, redirections are performed, but do not
6246affect the current shell environment. A redirection error causes the
6247command to exit with a non-zero status.
6248<P>
6249
6250If there is a command name left after expansion, execution proceeds as
6251described below. Otherwise, the command exits. If one of the expansions
6252contained a command substitution, the exit status of the command is
6253the exit status of the last command substitution performed. If there
6254were no command substitutions, the command exits with a status of zero.
6255<A NAME="lbBY">&nbsp;</A>
6256<H3>COMMAND EXECUTION</H3>
6257
6258After a command has been split into words, if it results in a
6259simple command and an optional list of arguments, the following
6260actions are taken.
6261<P>
6262
6263If the command name contains no slashes, the shell attempts to
6264locate it. If there exists a shell function by that name, that
6265function is invoked as described above in
6266<FONT SIZE=-1><B>FUNCTIONS</B>.
6267
6268</FONT>
6269If the name does not match a function, the shell searches for
6270it in the list of shell builtins. If a match is found, that
6271builtin is invoked.
6272<P>
6273
6274If the name is neither a shell function nor a builtin,
6275and contains no slashes,
6276<B>bash</B>
6277
6278searches each element of the
6279<FONT SIZE=-1><B>PATH</B>
6280
6281</FONT>
6282for a directory containing an executable file by that name.
6283<B>Bash</B>
6284
6285uses a hash table to remember the full pathnames of executable
6286files (see
6287<B>hash</B>
6288
6289under
6290<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
6291
6292</FONT>
6293below).
6294A full search of the directories in
6295<FONT SIZE=-1><B>PATH</B>
6296
6297</FONT>
6298is performed only if the command is not found in the hash table.
6299If the search is unsuccessful, the shell searches for a defined shell
6300function named <B>command_not_found_handle</B>.
d233b485
CR
6301If that function exists, it is invoked in a separate execution environment
6302with the original command and
17345e5a 6303the original command's arguments as its arguments, and the function's
d233b485 6304exit status becomes the exit status of that subshell.
17345e5a
JA
6305If that function is not defined, the shell prints an error
6306message and returns an exit status of 127.
6307<P>
6308
6309If the search is successful, or if the command name contains
6310one or more slashes, the shell executes the named program in a
6311separate execution environment.
6312Argument 0 is set to the name given, and the remaining arguments
6313to the command are set to the arguments given, if any.
6314<P>
6315
6316If this execution fails because the file is not in executable
6317format, and the file is not a directory, it is assumed to be
6318a <I>shell script</I>, a file
74091dd4
CR
6319containing shell commands, and the shell creates a
6320new instance of itself
6321to execute it.
6322This subshell reinitializes itself, so
17345e5a
JA
6323that the effect is as if a new shell had been invoked
6324to handle the script, with the exception that the locations of
6325commands remembered by the parent (see
6326<B>hash</B>
6327
6328below under
6329<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>)</FONT>
6330are retained by the child.
6331<P>
6332
6333If the program is a file beginning with
6334<B>#!</B>,
6335
6336the remainder of the first line specifies an interpreter
6337for the program. The shell executes the
6338specified interpreter on operating systems that do not
a0c0a00f 6339handle this executable format themselves. The arguments to the
17345e5a
JA
6340interpreter consist of a single optional argument following the
6341interpreter name on the first line of the program, followed
6342by the name of the program, followed by the command
6343arguments, if any.
6344<A NAME="lbBZ">&nbsp;</A>
6345<H3>COMMAND EXECUTION ENVIRONMENT</H3>
6346
6347The shell has an <I>execution environment</I>, which consists of the
6348following:
17345e5a
JA
6349<DL COMPACT>
6350<DT>*<DD>
6351open files inherited by the shell at invocation, as modified by
6352redirections supplied to the <B>exec</B> builtin
6353<DT>*<DD>
6354the current working directory as set by <B>cd</B>, <B>pushd</B>, or
6355<B>popd</B>, or inherited by the shell at invocation
6356<DT>*<DD>
6357the file creation mode mask as set by <B>umask</B> or inherited from
6358the shell's parent
6359<DT>*<DD>
6360current traps set by <B>trap</B>
6361<DT>*<DD>
6362shell parameters that are set by variable assignment or with <B>set</B>
6363or inherited from the shell's parent in the environment
6364<DT>*<DD>
6365shell functions defined during execution or inherited from the shell's
6366parent in the environment
6367<DT>*<DD>
6368options enabled at invocation (either by default or with command-line
6369arguments) or by <B>set</B>
6370<DT>*<DD>
6371options enabled by <B>shopt</B>
6372<DT>*<DD>
6373shell aliases defined with <B>alias</B>
6374<DT>*<DD>
6375various process IDs, including those of background jobs, the value
0001803f
CR
6376of <B>$$</B>, and the value of
6377<FONT SIZE=-1><B>PPID</B>
6378
6379</FONT>
17345e5a
JA
6380</DL>
6381<P>
6382
6383When a simple command other than a builtin or shell function
6384is to be executed, it
6385is invoked in a separate execution environment that consists of
74091dd4
CR
6386the following.
6387Unless otherwise noted, the values are inherited from the shell.
0001803f 6388
17345e5a
JA
6389<DL COMPACT>
6390<DT>*<DD>
6391the shell's open files, plus any modifications and additions specified
6392by redirections to the command
6393<DT>*<DD>
6394the current working directory
6395<DT>*<DD>
6396the file creation mode mask
6397<DT>*<DD>
6398shell variables and functions marked for export, along with variables
6399exported for the command, passed in the environment
6400<DT>*<DD>
6401traps caught by the shell are reset to the values inherited from the
6402shell's parent, and traps ignored by the shell are ignored
6403</DL>
6404<P>
6405
6406A command invoked in this separate environment cannot affect the
a0c0a00f 6407shell's execution environment.
17345e5a
JA
6408<P>
6409
74091dd4
CR
6410A <I>subshell</I> is a copy of the shell process.
6411<P>
6412
17345e5a
JA
6413Command substitution, commands grouped with parentheses,
6414and asynchronous commands are invoked in a
6415subshell environment that is a duplicate of the shell environment,
6416except that traps caught by the shell are reset to the values
6417that the shell inherited from its parent at invocation. Builtin
6418commands that are invoked as part of a pipeline are also executed in a
6419subshell environment. Changes made to the subshell environment
6420cannot affect the shell's execution environment.
6421<P>
6422
6423Subshells spawned to execute command substitutions inherit the value of
d233b485 6424the <B>-e</B> option from the parent shell. When not in <I>posix mode</I>,
495aee44 6425<B>bash</B> clears the <B>-e</B> option in such subshells.
17345e5a
JA
6426<P>
6427
6428If a command is followed by a <B>&amp;</B> and job control is not active, the
6429default standard input for the command is the empty file <I>/dev/null</I>.
6430Otherwise, the invoked command inherits the file descriptors of the calling
6431shell as modified by redirections.
6432<A NAME="lbCA">&nbsp;</A>
6433<H3>ENVIRONMENT</H3>
6434
6435When a program is invoked it is given an array of strings
6436called the
6437<I>environment</I>.
6438
a0c0a00f 6439This is a list of
17345e5a
JA
6440<I>name</I>-<I>value</I> pairs, of the form
6441<I>name</I>=value.
6442
6443<P>
6444
6445The shell provides several ways to manipulate the environment.
6446On invocation, the shell scans its own environment and
6447creates a parameter for each name found, automatically marking
6448it for
6449<I>export</I>
6450
6451to child processes. Executed commands inherit the environment.
6452The
6453<B>export</B>
6454
6455and
6456<B>declare -x</B>
6457
6458commands allow parameters and functions to be added to and
6459deleted from the environment. If the value of a parameter
6460in the environment is modified, the new value becomes part
6461of the environment, replacing the old. The environment
6462inherited by any executed command consists of the shell's
6463initial environment, whose values may be modified in the shell,
6464less any pairs removed by the
6465<B>unset</B>
6466
6467command, plus any additions via the
6468<B>export</B>
6469
6470and
6471<B>declare -x</B>
6472
6473commands.
6474<P>
6475
6476The environment for any
6477<I>simple command</I>
6478
6479or function may be augmented temporarily by prefixing it with
6480parameter assignments, as described above in
6481<FONT SIZE=-1><B>PARAMETERS</B>.
6482
6483</FONT>
6484These assignment statements affect only the environment seen
6485by that command.
6486<P>
6487
a0c0a00f 6488If the
17345e5a
JA
6489<B>-k</B>
6490
6491option is set (see the
6492<B>set</B>
6493
6494builtin command below), then
6495<I>all</I>
6496
6497parameter assignments are placed in the environment for a command,
6498not just those that precede the command name.
6499<P>
6500
6501When
6502<B>bash</B>
6503
6504invokes an external command, the variable
6505<B>_</B>
6506
ac50fbac 6507is set to the full filename of the command and passed to that
17345e5a
JA
6508command in its environment.
6509<A NAME="lbCB">&nbsp;</A>
6510<H3>EXIT STATUS</H3>
6511
17345e5a
JA
6512The exit status of an executed command is the value returned by the
6513<I>waitpid</I> system call or equivalent function. Exit statuses
6514fall between 0 and 255, though, as explained below, the shell may
6515use values above 125 specially. Exit statuses from shell builtins and
a0c0a00f 6516compound commands are also limited to this range. Under certain
17345e5a
JA
6517circumstances, the shell will use special values to indicate specific
6518failure modes.
6519<P>
6520
a0c0a00f 6521For the shell's purposes, a command which exits with a
17345e5a
JA
6522zero exit status has succeeded. An exit status of zero
6523indicates success. A non-zero exit status indicates failure.
6524When a command terminates on a fatal signal <I>N</I>, <B>bash</B> uses
6525the value of 128+<I>N</I> as the exit status.
6526<P>
6527
6528If a command is not found, the child process created to
6529execute it returns a status of 127. If a command is found
6530but is not executable, the return status is 126.
6531<P>
6532
6533If a command fails because of an error during expansion or redirection,
6534the exit status is greater than zero.
6535<P>
6536
6537Shell builtin commands return a status of 0 (<I>true</I>) if
6538successful, and non-zero (<I>false</I>) if an error occurs
a0c0a00f
CR
6539while they execute.
6540All builtins return an exit status of 2 to indicate incorrect usage,
6541generally invalid options or missing arguments.
17345e5a
JA
6542<P>
6543
74091dd4
CR
6544The exit status of the last command is available in the special
6545parameter $?.
6546<P>
6547
17345e5a
JA
6548<B>Bash</B> itself returns the exit status of the last command
6549executed, unless a syntax error occurs, in which case it exits
6550with a non-zero value. See also the <B>exit</B> builtin
6551command below.
6552<A NAME="lbCC">&nbsp;</A>
6553<H3>SIGNALS</H3>
6554
6555When <B>bash</B> is interactive, in the absence of any traps, it ignores
6556<FONT SIZE=-1><B>SIGTERM</B>
6557
6558</FONT>
6559(so that <B>kill 0</B> does not kill an interactive shell),
6560and
6561<FONT SIZE=-1><B>SIGINT</B>
6562
6563</FONT>
6564is caught and handled (so that the <B>wait</B> builtin is interruptible).
6565In all cases, <B>bash</B> ignores
6566<FONT SIZE=-1><B>SIGQUIT</B>.
6567
6568</FONT>
6569If job control is in effect,
6570<B>bash</B>
6571
6572ignores
6573<FONT SIZE=-1><B>SIGTTIN</B>,
6574
6575</FONT>
6576<FONT SIZE=-1><B>SIGTTOU</B>,
6577
6578</FONT>
6579and
6580<FONT SIZE=-1><B>SIGTSTP</B>.
6581
6582</FONT>
6583<P>
6584
6585Non-builtin commands run by <B>bash</B> have signal handlers
6586set to the values inherited by the shell from its parent.
6587When job control is not in effect, asynchronous commands
6588ignore
6589<FONT SIZE=-1><B>SIGINT</B>
6590
6591</FONT>
6592and
6593<FONT SIZE=-1><B>SIGQUIT</B>
6594
6595</FONT>
6596in addition to these inherited handlers.
6597Commands run as a result of command substitution ignore the
6598keyboard-generated job control signals
6599<FONT SIZE=-1><B>SIGTTIN</B>,
6600
6601</FONT>
6602<FONT SIZE=-1><B>SIGTTOU</B>,
6603
6604</FONT>
6605and
6606<FONT SIZE=-1><B>SIGTSTP</B>.
6607
6608</FONT>
6609<P>
6610
6611The shell exits by default upon receipt of a
6612<FONT SIZE=-1><B>SIGHUP</B>.
6613
6614</FONT>
6615Before exiting, an interactive shell resends the
6616<FONT SIZE=-1><B>SIGHUP</B>
6617
6618</FONT>
6619to all jobs, running or stopped.
6620Stopped jobs are sent
6621<FONT SIZE=-1><B>SIGCONT</B>
6622
6623</FONT>
6624to ensure that they receive the
6625<FONT SIZE=-1><B>SIGHUP</B>.
6626
6627</FONT>
6628To prevent the shell from
6629sending the signal to a particular job, it should be removed from the
a0c0a00f 6630jobs table with the
17345e5a
JA
6631<B>disown</B>
6632
6633builtin (see
6634<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
6635
6636</FONT>
a0c0a00f 6637below) or marked
17345e5a
JA
6638to not receive
6639<FONT SIZE=-1><B>SIGHUP</B>
6640
6641</FONT>
6642using
6643<B>disown -h</B>.
6644
6645<P>
6646
6647If the
6648<B>huponexit</B>
6649
6650shell option has been set with
6651<B>shopt</B>,
6652
6653<B>bash</B>
6654
a0c0a00f 6655sends a
17345e5a
JA
6656<FONT SIZE=-1><B>SIGHUP</B>
6657
6658</FONT>
6659to all jobs when an interactive login shell exits.
6660<P>
6661
6662If <B>bash</B> is waiting for a command to complete and receives a signal
6663for which a trap has been set, the trap will not be executed until
a0c0a00f 6664the command completes.
17345e5a
JA
6665When <B>bash</B> is waiting for an asynchronous command via the <B>wait</B>
6666builtin, the reception of a signal for which a trap has been set will
6667cause the <B>wait</B> builtin to return immediately with an exit status
6668greater than 128, immediately after which the trap is executed.
74091dd4
CR
6669<P>
6670
6671When job control is not enabled, and <B>bash</B> is waiting for a foreground
6672command to complete, the shell receives keyboard-generated signals
6673such as
6674<FONT SIZE=-1><B>SIGINT</B>
6675
6676</FONT>
6677(usually generated by <B>^C</B>) that users commonly intend to send
6678to that command.
6679This happens because the shell and the command are in the
6680same process group as the terminal, and <B>^C</B> sends
6681<FONT SIZE=-1><B>SIGINT</B>
6682
6683</FONT>
6684to all processes in that process group.
6685<P>
6686
6687When <B>bash</B> is running without job control enabled and receives
6688<FONT SIZE=-1><B>SIGINT</B>
6689
6690</FONT>
6691while waiting for a foreground command, it waits until that foreground
6692command terminates and then decides what to do about the
6693<FONT SIZE=-1><B>SIGINT</B>:
6694
6695</FONT>
6696<DL COMPACT>
6697<DT>1.<DD>
6698If the command terminates due to the
6699<FONT SIZE=-1><B>SIGINT</B>,
6700
6701</FONT>
6702<B>bash</B> concludes
6703that the user meant to end the entire script, and acts on the
6704<FONT SIZE=-1><B>SIGINT</B>
6705
6706</FONT>
6707(e.g., by running a
6708<FONT SIZE=-1><B>SIGINT</B>
6709
6710</FONT>
6711trap or exiting itself);
6712<DT>2.<DD>
6713If the command does not terminate due to
6714<FONT SIZE=-1><B>SIGINT</B>,
6715
6716</FONT>
6717the program handled the
6718<FONT SIZE=-1><B>SIGINT</B>
6719
6720</FONT>
6721itself and did not treat it as a fatal signal.
6722In that case, <B>bash</B> does not treat
6723<FONT SIZE=-1><B>SIGINT</B>
6724
6725</FONT>
6726as a fatal signal, either, instead assuming that the
6727<FONT SIZE=-1><B>SIGINT</B>
6728
6729</FONT>
6730was used as part of the program's normal operation
6731(e.g., emacs uses it to abort editing
6732commands) or deliberately discarded.
6733However, <B>bash</B> will run any
6734trap set on
6735<FONT SIZE=-1><B>SIGINT</B>,
6736
6737</FONT>
6738as it does with any other trapped signal it
6739receives while it is waiting for the foreground command to
6740complete, for compatibility.
6741</DL>
17345e5a
JA
6742<A NAME="lbCD">&nbsp;</A>
6743<H3>JOB CONTROL</H3>
6744
6745<I>Job control</I>
6746
6747refers to the ability to selectively stop (<I>suspend</I>)
6748the execution of processes and continue (<I>resume</I>)
6749their execution at a later point. A user typically employs
6750this facility via an interactive interface supplied jointly
0001803f 6751by the operating system kernel's terminal driver and
17345e5a
JA
6752<B>bash</B>.
6753
6754<P>
6755
6756The shell associates a
6757<I>job</I>
6758
6759with each pipeline. It keeps a table of currently executing
6760jobs, which may be listed with the
6761<B>jobs</B>
6762
6763command. When
6764<B>bash</B>
6765
6766starts a job asynchronously (in the
6767<I>background</I>),
6768
6769it prints a line that looks like:
6770<DL COMPACT><DT><DD>
6771<P>
6772
6773[1] 25647
6774</DL>
6775
6776<P>
6777
6778indicating that this job is job number 1 and that the process ID
6779of the last process in the pipeline associated with this job is 25647.
6780All of the processes in a single pipeline are members of the same job.
6781<B>Bash</B>
6782
6783uses the
6784<I>job</I>
6785
6786abstraction as the basis for job control.
6787<P>
6788
6789To facilitate the implementation of the user interface to job
6790control, the operating system maintains the notion of a <I>current terminal
6791process group ID</I>. Members of this process group (processes whose
6792process group ID is equal to the current terminal process group ID)
6793receive keyboard-generated signals such as
6794<FONT SIZE=-1><B>SIGINT</B>.
6795
6796</FONT>
6797These processes are said to be in the
6798<I>foreground</I>.
6799
6800<I>Background</I>
6801
6802processes are those whose process group ID differs from the terminal's;
6803such processes are immune to keyboard-generated signals.
0001803f
CR
6804Only foreground processes are allowed to read from or, if the
6805user so specifies with <TT>stty tostop</TT>, write to the
6806terminal.
6807Background processes which attempt to read from (write to when
6808<TT>stty tostop</TT> is in effect) the
a0c0a00f 6809terminal are sent a
17345e5a
JA
6810<FONT SIZE=-1><B>SIGTTIN (SIGTTOU)</B>
6811
6812</FONT>
8868edaf 6813signal by the kernel's terminal driver,
17345e5a
JA
6814which, unless caught, suspends the process.
6815<P>
6816
6817If the operating system on which
6818<B>bash</B>
6819
6820is running supports
6821job control,
6822<B>bash</B>
6823
6824contains facilities to use it.
6825Typing the
6826<I>suspend</I>
6827
6828character (typically
6829<B>^Z</B>,
6830
6831Control-Z) while a process is running
a0c0a00f 6832causes that process to be stopped and returns control to
17345e5a
JA
6833<B>bash</B>.
6834
6835Typing the
6836<I>delayed suspend</I>
6837
6838character (typically
6839<B>^Y</B>,
6840
6841Control-Y) causes the process to be stopped when it
6842attempts to read input from the terminal, and control to
6843be returned to
6844<B>bash</B>.
6845
6846The user may then manipulate the state of this job, using the
6847<B>bg</B>
6848
6849command to continue it in the background, the
6850<B>fg</B>
6851
6852command to continue it in the foreground, or
6853the
6854<B>kill</B>
6855
6856command to kill it. A <B>^Z</B> takes effect immediately,
6857and has the additional side effect of causing pending output
6858and typeahead to be discarded.
6859<P>
6860
6861There are a number of ways to refer to a job in the shell.
6862The character
6863<B>%</B>
6864
6865introduces a job specification (<I>jobspec</I>). Job number
6866<I>n</I>
6867
6868may be referred to as
6869<B>%n</B>.
6870
6871A job may also be referred to using a prefix of the name used to
6872start it, or using a substring that appears in its command line.
6873For example,
6874<B>%ce</B>
6875
6876refers to a stopped
8868edaf
CR
6877job whose command name begins with
6878<B>ce</B>.
17345e5a 6879
8868edaf 6880If a prefix matches more than one job,
17345e5a
JA
6881<B>bash</B>
6882
6883reports an error. Using
6884<B>%?ce</B>,
6885
6886on the other hand, refers to any job containing the string
6887<B>ce</B>
6888
6889in its command line. If the substring matches more than one job,
6890<B>bash</B>
6891
6892reports an error. The symbols
6893<B>%%</B>
6894
6895and
6896<B>%+</B>
6897
6898refer to the shell's notion of the
6899<I>current job</I>,
6900
6901which is the last job stopped while it was in
6902the foreground or started in the background.
a0c0a00f 6903The
17345e5a
JA
6904<I>previous job</I>
6905
6906may be referenced using
6907<B>%-</B>.
6908
6909If there is only a single job, <B>%+</B> and <B>%-</B> can both be used
6910to refer to that job.
6911In output pertaining to jobs (e.g., the output of the
6912<B>jobs</B>
6913
6914command), the current job is always flagged with a
6915<B>+</B>,
6916
6917and the previous job with a
6918<B>-</B>.
6919
6920A single % (with no accompanying job specification) also refers to the
6921current job.
6922<P>
6923
6924Simply naming a job can be used to bring it into the
6925foreground:
6926<B>%1</B>
6927
6928is a synonym for
6929<B>``fg %1''</B>,
6930bringing job 1 from the background into the foreground.
6931Similarly,
6932<B>``%1 &amp;''</B>
6933
6934resumes job 1 in the background, equivalent to
6935<B>``bg %1''</B>.
6936<P>
6937
6938The shell learns immediately whenever a job changes state.
6939Normally,
6940<B>bash</B>
6941
6942waits until it is about to print a prompt before reporting
6943changes in a job's status so as to not interrupt
a0c0a00f 6944any other output. If the
17345e5a
JA
6945<B>-b</B>
6946
6947option to the
6948<B>set</B>
6949
6950builtin command
6951is enabled,
6952<B>bash</B>
6953
6954reports such changes immediately.
6955Any trap on
6956<FONT SIZE=-1><B>SIGCHLD</B>
6957
6958</FONT>
6959is executed for each child that exits.
6960<P>
6961
6962If an attempt to exit
6963<B>bash</B>
6964
6965is made while jobs are stopped (or, if the <B>checkjobs</B> shell option has
6966been enabled using the <B>shopt</B> builtin, running), the shell prints a
6967warning message, and, if the <B>checkjobs</B> option is enabled, lists the
6968jobs and their statuses.
6969The
6970<B>jobs</B>
6971
a0c0a00f 6972command may then be used to inspect their status.
17345e5a
JA
6973If a second attempt to exit is made without an intervening command,
6974the shell does not print another warning, and any stopped
6975jobs are terminated.
d233b485
CR
6976<P>
6977
6978When the shell is waiting for a job or process using the <B>wait</B>
6979builtin, and job control is enabled, <B>wait</B> will return when the
8868edaf 6980job changes state. The <B>-f</B> option causes <B>wait</B> to wait
d233b485 6981until the job or process terminates before returning.
17345e5a
JA
6982<A NAME="lbCE">&nbsp;</A>
6983<H3>PROMPTING</H3>
6984
a0c0a00f 6985When executing interactively,
17345e5a
JA
6986<B>bash</B>
6987
6988displays the primary prompt
6989<FONT SIZE=-1><B>PS1</B>
6990
6991</FONT>
6992when it is ready to read a command, and the secondary prompt
6993<FONT SIZE=-1><B>PS2</B>
6994
6995</FONT>
6996when it needs more input to complete a command.
6997<B>Bash</B>
6998
a0c0a00f 6999displays
d233b485 7000<FONT SIZE=-1><B>PS0</B>
a0c0a00f 7001
d233b485 7002</FONT>
a0c0a00f
CR
7003after it reads a command but before executing it.
7004<B>Bash</B>
7005
d233b485
CR
7006displays
7007<FONT SIZE=-1><B>PS4</B>
7008
7009</FONT>
7010as described above
7011before tracing each command when the <B>-x</B> option is enabled.
7012<B>Bash</B>
7013
17345e5a
JA
7014allows these prompt strings to be customized by inserting a number of
7015backslash-escaped special characters that are decoded as follows:
7016<DL COMPACT><DT><DD>
7017
7018<DL COMPACT>
7019<DT><B>\a</B>
7020
7021<DD>
7022an ASCII bell character (07)
7023<DT><B>\d</B>
7024
7025<DD>
7026the date in &quot;Weekday Month Date&quot; format (e.g., &quot;Tue May 26&quot;)
7027<DT><B>\D{</B><I>format</I>}
7028
7029<DD>
7030the <I>format</I> is passed to <I>strftime</I>(3) and the result is inserted
7031into the prompt string; an empty <I>format</I> results in a locale-specific
7032time representation. The braces are required
7033<DT><B>\e</B>
7034
7035<DD>
7036an ASCII escape character (033)
7037<DT><B>\h</B>
7038
7039<DD>
7040the hostname up to the first `.'
7041<DT><B>\H</B>
7042
7043<DD>
7044the hostname
7045<DT><B>\j</B>
7046
7047<DD>
7048the number of jobs currently managed by the shell
7049<DT><B>\l</B>
7050
7051<DD>
7052the basename of the shell's terminal device name
7053<DT><B>\n</B>
7054
7055<DD>
7056newline
7057<DT><B>\r</B>
7058
7059<DD>
7060carriage return
7061<DT><B>\s</B>
7062
7063<DD>
7064the name of the shell, the basename of
7065<B>$0</B>
7066
7067(the portion following the final slash)
7068<DT><B>\t</B>
7069
7070<DD>
7071the current time in 24-hour HH:MM:SS format
7072<DT><B>\T</B>
7073
7074<DD>
7075the current time in 12-hour HH:MM:SS format
7076<DT><B>\@</B>
7077
7078<DD>
7079the current time in 12-hour am/pm format
7080<DT><B>\A</B>
7081
7082<DD>
7083the current time in 24-hour HH:MM format
7084<DT><B>\u</B>
7085
7086<DD>
7087the username of the current user
7088<DT><B>\v</B>
7089
7090<DD>
7091the version of <B>bash</B> (e.g., 2.00)
7092<DT><B>\V</B>
7093
7094<DD>
7095the release of <B>bash</B>, version + patch level (e.g., 2.00.0)
7096<DT><B>\w</B>
7097
7098<DD>
74091dd4
CR
7099the value of the <B>PWD</B> shell variable (<B>$PWD</B>),
7100with
0001803f
CR
7101<FONT SIZE=-1><B>$HOME</B>
7102
7103</FONT>
7104abbreviated with a tilde
7105(uses the value of the
7106<FONT SIZE=-1><B>PROMPT_DIRTRIM</B>
7107
7108</FONT>
7109variable)
17345e5a
JA
7110<DT><B>\W</B>
7111
7112<DD>
74091dd4
CR
7113the basename of <B>$PWD</B>,
7114with
0001803f
CR
7115<FONT SIZE=-1><B>$HOME</B>
7116
7117</FONT>
17345e5a
JA
7118abbreviated with a tilde
7119<DT><B>\!</B>
7120
7121<DD>
7122the history number of this command
7123<DT><B>\#</B>
7124
7125<DD>
7126the command number of this command
7127<DT><B>\$</B>
7128
7129<DD>
7130if the effective UID is 0, a
7131<B>#</B>,
7132
7133otherwise a
7134<B>$</B>
7135
7136<DT><B>\</B><I>nnn</I>
7137
7138<DD>
7139the character corresponding to the octal number <I>nnn</I>
7140<DT><B>\\</B>
7141
7142<DD>
7143a backslash
7144<DT><B>\[</B>
7145
7146<DD>
7147begin a sequence of non-printing characters, which could be used to
7148embed a terminal control sequence into the prompt
7149<DT><B>\]</B>
7150
7151<DD>
7152end a sequence of non-printing characters
7153
7154</DL></DL>
7155
7156<P>
7157
7158The command number and the history number are usually different:
7159the history number of a command is its position in the history
7160list, which may include commands restored from the history file
7161(see
7162<FONT SIZE=-1><B>HISTORY</B>
7163
7164</FONT>
7165below), while the command number is the position in the sequence
7166of commands executed during the current shell session.
7167After the string is decoded, it is expanded via
7168parameter expansion, command substitution, arithmetic
7169expansion, and quote removal, subject to the value of the
7170<B>promptvars</B>
7171
7172shell option (see the description of the
7173<B>shopt</B>
7174
7175command under
7176<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
7177
7178</FONT>
7179below).
8868edaf
CR
7180This can have unwanted side effects if escaped portions of the string
7181appear within command substitution or contain characters special to
7182word expansion.
17345e5a
JA
7183<A NAME="lbCF">&nbsp;</A>
7184<H3>READLINE</H3>
7185
7186This is the library that handles reading input when using an interactive
7187shell, unless the
7188<B>--noediting</B>
7189
7190option is given at shell invocation.
7191Line editing is also used when using the <B>-e</B> option to the
7192<B>read</B> builtin.
495aee44 7193By default, the line editing commands are similar to those of Emacs.
17345e5a
JA
7194A vi-style line editing interface is also available.
7195Line editing can be enabled at any time using the
7196<B>-o emacs</B>
7197
7198or
7199<B>-o vi</B>
7200
7201options to the
7202<B>set</B>
7203
7204builtin (see
7205<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
7206
7207</FONT>
7208below).
7209To turn off line editing after the shell is running, use the
7210<B>+o emacs</B>
7211
7212or
7213<B>+o vi</B>
7214
7215options to the
7216<B>set</B>
7217
7218builtin.
7219<A NAME="lbCG">&nbsp;</A>
7220<H4>Readline Notation</H4>
7221
495aee44 7222In this section, the Emacs-style notation is used to denote
17345e5a 7223keystrokes. Control keys are denoted by C-<I>key</I>, e.g., C-n
a0c0a00f 7224means Control-N. Similarly,
17345e5a
JA
7225<I>meta</I>
7226
7227keys are denoted by M-<I>key</I>, so M-x means Meta-X. (On keyboards
a0c0a00f 7228without a
17345e5a
JA
7229<I>meta</I>
7230
7231key, M-<I>x</I> means ESC <I>x</I>, i.e., press the Escape key
7232then the
7233<I>x</I>
7234
7235key. This makes ESC the <I>meta prefix</I>.
7236The combination M-C-<I>x</I> means ESC-Control-<I>x</I>,
7237or press the Escape key
7238then hold the Control key while pressing the
7239<I>x</I>
7240
7241key.)
7242<P>
7243
7244Readline commands may be given numeric
7245<I>arguments</I>,
7246
7247which normally act as a repeat count.
7248Sometimes, however, it is the sign of the argument that is significant.
7249Passing a negative argument to a command that acts in the forward
7250direction (e.g., <B>kill-line</B>) causes that command to act in a
a0c0a00f 7251backward direction.
17345e5a
JA
7252Commands whose behavior with arguments deviates from this are noted
7253below.
7254<P>
7255
7256When a command is described as <I>killing</I> text, the text
7257deleted is saved for possible future retrieval
7258(<I>yanking</I>). The killed text is saved in a
7259<I>kill ring</I>. Consecutive kills cause the text to be
a0c0a00f 7260accumulated into one unit, which can be yanked all at once.
17345e5a
JA
7261Commands which do not kill text separate the chunks of text
7262on the kill ring.
7263<A NAME="lbCH">&nbsp;</A>
7264<H4>Readline Initialization</H4>
7265
17345e5a
JA
7266Readline is customized by putting commands in an initialization
7267file (the <I>inputrc</I> file).
7268The name of this file is taken from the value of the
7269<FONT SIZE=-1><B>INPUTRC</B>
7270
7271</FONT>
7272variable. If that variable is unset, the default is
7273<A HREF="file:~/.inputrc"><I>~/.inputrc</I></A>.
7274
8868edaf
CR
7275If that file does not exist or cannot be read, the ultimate default is
7276<A HREF="file:/etc/inputrc"><I>/etc/inputrc</I></A>.
7277
17345e5a
JA
7278When a program which uses the readline library starts up, the
7279initialization file is read, and the key bindings and variables
7280are set.
7281There are only a few basic constructs allowed in the
7282readline initialization file.
7283Blank lines are ignored.
7284Lines beginning with a <B>#</B> are comments.
7285Lines beginning with a <B>$</B> indicate conditional constructs.
7286Other lines denote key bindings and variable settings.
7287<P>
7288
7289The default key-bindings may be changed with an
a0c0a00f 7290<I>inputrc</I>
17345e5a
JA
7291
7292file.
7293Other programs that use this library may add their own commands
7294and bindings.
7295<P>
7296
7297For example, placing
7298<DL COMPACT><DT><DD>
7299<P>
7300
7301M-Control-u: universal-argument
7302</DL>
7303
7304or
7305<DL COMPACT><DT><DD>
7306C-Meta-u: universal-argument
7307</DL>
7308
a0c0a00f 7309into the
17345e5a
JA
7310<I>inputrc</I>
7311
7312would make M-C-u execute the readline command
7313<I>universal-argument</I>.
7314
7315<P>
7316
7317The following symbolic character names are recognized:
7318<I>RUBOUT</I>,
7319
7320<I>DEL</I>,
7321
7322<I>ESC</I>,
7323
7324<I>LFD</I>,
7325
7326<I>NEWLINE</I>,
7327
7328<I>RET</I>,
7329
7330<I>RETURN</I>,
7331
7332<I>SPC</I>,
7333
7334<I>SPACE</I>,
7335
7336and
7337<I>TAB</I>.
7338
7339<P>
7340
7341In addition to command names, readline allows keys to be bound
7342to a string that is inserted when the key is pressed (a <I>macro</I>).
7343<A NAME="lbCI">&nbsp;</A>
7344<H4>Readline Key Bindings</H4>
7345
17345e5a
JA
7346The syntax for controlling key bindings in the
7347<I>inputrc</I>
7348
7349file is simple. All that is required is the name of the
7350command or the text of a macro and a key sequence to which
a0c0a00f 7351it should be bound. The name may be specified in one of two ways:
17345e5a
JA
7352as a symbolic key name, possibly with <I>Meta-</I> or <I>Control-</I>
7353prefixes, or as a key sequence.
7354<P>
7355
7356When using the form <B>keyname</B>:<I>function-name</I> or <I>macro</I>,
7357<I>keyname</I>
7358
7359is the name of a key spelled out in English. For example:
7360<P>
7361<DL COMPACT><DT><DD>
7362Control-u: universal-argument
7363<BR>
7364
7365Meta-Rubout: backward-kill-word
7366<BR>
7367
7368Control-o: &quot;&gt; output&quot;
7369</DL>
7370
7371<P>
7372
7373In the above example,
7374<I>C-u</I>
7375
7376is bound to the function
7377<B>universal-argument</B>,
7378
7379<I>M-DEL</I>
7380
7381is bound to the function
7382<B>backward-kill-word</B>,
7383
7384and
7385<I>C-o</I>
7386
7387is bound to run the macro
7388expressed on the right hand side (that is, to insert the text
7389<TT>&gt; output</TT>
7390
7391into the line).
7392<P>
7393
7394In the second form, <B>&quot;keyseq&quot;</B>:<I>function-name</I> or <I>macro</I>,
7395<B>keyseq</B>
7396
7397differs from
7398<B>keyname</B>
7399
7400above in that strings denoting
7401an entire key sequence may be specified by placing the sequence
7402within double quotes. Some GNU Emacs style key escapes can be
7403used, as in the following example, but the symbolic character names
7404are not recognized.
7405<P>
7406<DL COMPACT><DT><DD>
7407&quot;\C-u&quot;: universal-argument
7408<BR>
7409
7410&quot;\C-x\C-r&quot;: re-read-init-file
7411<BR>
7412
7413&quot;\e[11~&quot;: &quot;Function Key 1&quot;
7414</DL>
7415
7416<P>
7417
7418In this example,
7419<I>C-u</I>
7420
7421is again bound to the function
7422<B>universal-argument</B>.
7423
7424<I>C-x C-r</I>
7425
7426is bound to the function
7427<B>re-read-init-file</B>,
7428
a0c0a00f 7429and
17345e5a
JA
7430<I>ESC [ 1 1 ~</I>
7431
7432is bound to insert the text
7433<TT>Function Key 1</TT>.
7434
7435<P>
7436
7437The full set of GNU Emacs style escape sequences is
7438<DL COMPACT><DT><DD>
7439
7440<DL COMPACT>
7441<DT><B>\C-</B>
7442
7443<DD>
7444control prefix
7445<DT><B>\M-</B>
7446
7447<DD>
7448meta prefix
7449<DT><B>\e</B>
7450
7451<DD>
7452an escape character
7453<DT><B>\\</B>
7454
7455<DD>
7456backslash
7457<DT><B>\</B>
7458
7459<DD>
7460literal &quot;
7461<DT><B>\aq</B>
7462
7463<DD>
7464literal aq
7465</DL></DL>
7466
7467
7468<P>
7469
7470In addition to the GNU Emacs style escape sequences, a second
7471set of backslash escapes is available:
7472<DL COMPACT><DT><DD>
7473
7474<DL COMPACT>
7475<DT><B>\a</B>
7476
7477<DD>
7478alert (bell)
7479<DT><B>\b</B>
7480
7481<DD>
7482backspace
7483<DT><B>\d</B>
7484
7485<DD>
7486delete
7487<DT><B>\f</B>
7488
7489<DD>
7490form feed
7491<DT><B>\n</B>
7492
7493<DD>
7494newline
7495<DT><B>\r</B>
7496
7497<DD>
7498carriage return
7499<DT><B>\t</B>
7500
7501<DD>
7502horizontal tab
7503<DT><B>\v</B>
7504
7505<DD>
7506vertical tab
7507<DT><B>\</B><I>nnn</I>
7508
7509<DD>
7510the eight-bit character whose value is the octal value <I>nnn</I>
7511(one to three digits)
7512<DT><B>\x</B><I>HH</I>
7513
7514<DD>
7515the eight-bit character whose value is the hexadecimal value <I>HH</I>
7516(one or two hex digits)
7517</DL></DL>
7518
7519
7520<P>
7521
7522When entering the text of a macro, single or double quotes must
7523be used to indicate a macro definition.
7524Unquoted text is assumed to be a function name.
7525In the macro body, the backslash escapes described above are expanded.
7526Backslash will quote any other character in the macro text,
7527including &quot; and aq.
7528<P>
7529
7530<B>Bash</B>
7531
7532allows the current readline key bindings to be displayed or modified
7533with the
7534<B>bind</B>
7535
7536builtin command. The editing mode may be switched during interactive
7537use by using the
7538<B>-o</B>
7539
7540option to the
7541<B>set</B>
7542
7543builtin command (see
7544<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
7545
7546</FONT>
7547below).
7548<A NAME="lbCJ">&nbsp;</A>
7549<H4>Readline Variables</H4>
7550
17345e5a
JA
7551Readline has variables that can be used to further customize its
7552behavior. A variable may be set in the
7553<I>inputrc</I>
7554
7555file with a statement of the form
7556<DL COMPACT><DT><DD>
7557<P>
7558
7559<B>set</B> <I>variable-name</I> <I>value</I>
7560</DL>
7561
8868edaf
CR
7562or using the <B>bind</B> builtin command (see
7563<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
7564
7565</FONT>
7566below).
17345e5a
JA
7567<P>
7568
7569Except where noted, readline variables can take the values
7570<B>On</B>
7571
7572or
7573<B>Off</B>
7574
7575(without regard to case).
7576Unrecognized variable names are ignored.
7577When a variable value is read, empty or null values, &quot;on&quot; (case-insensitive),
7578and &quot;1&quot; are equivalent to <B>On</B>. All other values are equivalent to
7579<B>Off</B>.
7580The variables and their default values are:
7581<P>
7582
7583
7584<DL COMPACT>
74091dd4
CR
7585<DT><B>active-region-start-color </B>
7586
7587<DD>
7588A string variable that controls the text color and background when displaying
7589the text in the active region (see the description of
7590<B>enable-active-region</B> below).
7591This string must not take up any physical character positions on the display,
7592so it should consist only of terminal escape sequences.
7593It is output to the terminal before displaying the text in the active region.
7594This variable is reset to the default value whenever the terminal type changes.
7595The default value is the string that puts the terminal in standout mode,
7596as obtained from the terminal's terminfo description.
7597A sample value might be <TT>&quot;\e[01;33m&quot;</TT>.
7598<DT><B>active-region-end-color </B>
7599
7600<DD>
7601A string variable that &quot;undoes&quot; the effects of <B>active-region-start-color</B>
7602and restores &quot;normal&quot; terminal display appearance after displaying text
7603in the active region.
7604This string must not take up any physical character positions on the display,
7605so it should consist only of terminal escape sequences.
7606It is output to the terminal after displaying the text in the active region.
7607This variable is reset to the default value whenever the terminal type changes.
7608The default value is the string that restores the terminal from standout mode,
7609as obtained from the terminal's terminfo description.
7610A sample value might be <TT>&quot;\e[0m&quot;</TT>.
17345e5a
JA
7611<DT><B>bell-style (audible)</B>
7612
7613<DD>
7614Controls what happens when readline wants to ring the terminal bell.
7615If set to <B>none</B>, readline never rings the bell. If set to
7616<B>visible</B>, readline uses a visible bell if one is available.
7617If set to <B>audible</B>, readline attempts to ring the terminal's bell.
7618<DT><B>bind-tty-special-chars (On)</B>
7619
7620<DD>
7621If set to <B>On</B>, readline attempts to bind the control characters
7622treated specially by the kernel's terminal driver to their readline
7623equivalents.
a0c0a00f
CR
7624<DT><B>blink-matching-paren (Off)</B>
7625
7626<DD>
7627If set to <B>On</B>, readline attempts to briefly move the cursor to an
7628opening parenthesis when a closing parenthesis is inserted.
7629<DT><B>colored-completion-prefix (Off)</B>
7630
7631<DD>
7632If set to <B>On</B>, when listing completions, readline displays the
7633common prefix of the set of possible completions using a different color.
7634The color definitions are taken from the value of the <B>LS_COLORS</B>
7635environment variable.
74091dd4
CR
7636If there is a color definition in <B>$LS_COLORS</B> for the custom suffix
7637&quot;readline-colored-completion-prefix&quot;, readline uses this color for
7638the common prefix instead of its default.
ac50fbac
CR
7639<DT><B>colored-stats (Off)</B>
7640
7641<DD>
7642If set to <B>On</B>, readline displays possible completions using different
a0c0a00f 7643colors to indicate their file type.
ac50fbac
CR
7644The color definitions are taken from the value of the <B>LS_COLORS</B>
7645environment variable.
17345e5a
JA
7646<DT><B>comment-begin (``#'')</B>
7647
7648<DD>
7649The string that is inserted when the readline
7650<B>insert-comment</B>
7651
7652command is executed.
7653This command is bound to
7654<B>M-#</B>
7655
7656in emacs mode and to
7657<B>#</B>
7658
7659in vi command mode.
a0c0a00f
CR
7660<DT><B>completion-display-width (-1)</B>
7661
7662<DD>
7663The number of screen columns used to display possible matches
7664when performing completion.
7665The value is ignored if it is less than 0 or greater than the terminal
7666screen width.
7667A value of 0 will cause matches to be displayed one per line.
7668The default value is -1.
17345e5a
JA
7669<DT><B>completion-ignore-case (Off)</B>
7670
7671<DD>
7672If set to <B>On</B>, readline performs filename matching and completion
7673in a case-insensitive fashion.
a0c0a00f
CR
7674<DT><B>completion-map-case (Off)</B>
7675
7676<DD>
7677If set to <B>On</B>, and <B>completion-ignore-case</B> is enabled, readline
7678treats hyphens (<I>-</I>) and underscores (<I>_</I>) as equivalent when
7679performing case-insensitive filename matching and completion.
17345e5a
JA
7680<DT><B>completion-prefix-display-length (0)</B>
7681
7682<DD>
7683The length in characters of the common prefix of a list of possible
7684completions that is displayed without modification. When set to a
7685value greater than zero, common prefixes longer than this value are
7686replaced with an ellipsis when displaying possible completions.
7687<DT><B>completion-query-items (100)</B>
7688
7689<DD>
7690This determines when the user is queried about viewing
7691the number of possible completions
7692generated by the <B>possible-completions</B> command.
8868edaf
CR
7693It may be set to any integer value greater than or equal to zero.
7694If the number of possible completions is greater than
7695or equal to the value of this variable,
7696readline will ask whether or not the user wishes to view them;
7697otherwise they are simply listed on the terminal.
74091dd4
CR
7698A zero value means readline should never ask; negative values are
7699treated as zero.
17345e5a
JA
7700<DT><B>convert-meta (On)</B>
7701
7702<DD>
7703If set to <B>On</B>, readline will convert characters with the
7704eighth bit set to an ASCII key sequence
7705by stripping the eighth bit and prefixing an
7706escape character (in effect, using escape as the <I>meta prefix</I>).
a0c0a00f
CR
7707The default is <I>On</I>, but readline will set it to <I>Off</I> if the
7708locale contains eight-bit characters.
74091dd4
CR
7709This variable is dependent on the <B>LC_CTYPE</B> locale category, and
7710may change if the locale is changed.
17345e5a
JA
7711<DT><B>disable-completion (Off)</B>
7712
7713<DD>
7714If set to <B>On</B>, readline will inhibit word completion. Completion
7715characters will be inserted into the line as if they had been
7716mapped to <B>self-insert</B>.
a0c0a00f
CR
7717<DT><B>echo-control-characters (On)</B>
7718
7719<DD>
7720When set to <B>On</B>, on operating systems that indicate they support it,
7721readline echoes a character corresponding to a signal generated from the
7722keyboard.
17345e5a
JA
7723<DT><B>editing-mode (emacs)</B>
7724
7725<DD>
7726Controls whether readline begins with a set of key bindings similar
495aee44 7727to <I>Emacs</I> or <I>vi</I>.
17345e5a
JA
7728<B>editing-mode</B>
7729
7730can be set to either
7731<B>emacs</B>
7732
7733or
7734<B>vi</B>.
7735
d233b485
CR
7736<DT><B>emacs-mode-string (@)</B>
7737
7738<DD>
7739If the <I>show-mode-in-prompt</I> variable is enabled,
7740this string is displayed immediately before the last line of the primary
7741prompt when emacs editing mode is active. The value is expanded like a
7742key binding, so the standard set of meta- and control prefixes and
7743backslash escape sequences is available.
7744Use the \1 and \2 escapes to begin and end sequences of
7745non-printing characters, which can be used to embed a terminal control
7746sequence into the mode string.
74091dd4
CR
7747<DT><B>enable-active-region (On)</B>
7748
7749<DD>
7750The <I>point</I> is the current cursor position, and <I>mark</I> refers
7751to a saved cursor position.
7752The text between the point and mark is referred to as the <I>region</I>.
7753When this variable is set to <I>On</I>, readline allows certain commands
7754to designate the region as <I>active</I>.
7755When the region is active, readline highlights the text in the region using
7756the value of the <B>active-region-start-color</B>, which defaults to the
7757string that enables
7758the terminal's standout mode.
7759The active region shows the text inserted by bracketed-paste and any
7760matching text found by incremental and non-incremental history searches.
8868edaf 7761<DT><B>enable-bracketed-paste (On)</B>
0001803f
CR
7762
7763<DD>
74091dd4
CR
7764When set to <B>On</B>, readline configures the terminal to insert each
7765paste into the editing buffer as a single string of characters, instead
7766of treating each character as if it had been read from the keyboard.
7767This prevents readline from executing any editing commands bound to key
7768sequences appearing in the pasted text.
17345e5a
JA
7769<DT><B>enable-keypad (Off)</B>
7770
7771<DD>
7772When set to <B>On</B>, readline will try to enable the application
7773keypad when it is called. Some systems need this to enable the
7774arrow keys.
0001803f
CR
7775<DT><B>enable-meta-key (On)</B>
7776
7777<DD>
7778When set to <B>On</B>, readline will try to enable any meta modifier
7779key the terminal claims to support when it is called. On many terminals,
7780the meta key is used to send eight-bit characters.
17345e5a
JA
7781<DT><B>expand-tilde (Off)</B>
7782
7783<DD>
495aee44 7784If set to <B>On</B>, tilde expansion is performed when readline
17345e5a
JA
7785attempts word completion.
7786<DT><B>history-preserve-point (Off)</B>
7787
7788<DD>
495aee44 7789If set to <B>On</B>, the history code attempts to place point at the
17345e5a
JA
7790same location on each history line retrieved with <B>previous-history</B>
7791or <B>next-history</B>.
a0c0a00f 7792<DT><B>history-size (unset)</B>
17345e5a
JA
7793
7794<DD>
ac50fbac
CR
7795Set the maximum number of history entries saved in the history list.
7796If set to zero, any existing history entries are deleted and no new entries
7797are saved.
7798If set to a value less than zero, the number of history entries is not
7799limited.
a0c0a00f
CR
7800By default, the number of history entries is set to the value of the
7801<B>HISTSIZE</B> shell variable.
7802If an attempt is made to set <I>history-size</I> to a non-numeric value,
7803the maximum number of history entries will be set to 500.
17345e5a
JA
7804<DT><B>horizontal-scroll-mode (Off)</B>
7805
7806<DD>
7807When set to <B>On</B>, makes readline use a single line for display,
7808scrolling the input horizontally on a single screen line when it
7809becomes longer than the screen width rather than wrapping to a new line.
8868edaf 7810This setting is automatically enabled for terminals of height 1.
17345e5a
JA
7811<DT><B>input-meta (Off)</B>
7812
7813<DD>
7814If set to <B>On</B>, readline will enable eight-bit input (that is,
a0c0a00f 7815it will not strip the eighth bit from the characters it reads),
17345e5a
JA
7816regardless of what the terminal claims it can support. The name
7817<B>meta-flag</B>
7818
7819is a synonym for this variable.
a0c0a00f
CR
7820The default is <I>Off</I>, but readline will set it to <I>On</I> if the
7821locale contains eight-bit characters.
74091dd4
CR
7822This variable is dependent on the <B>LC_CTYPE</B> locale category, and
7823may change if the locale is changed.
17345e5a
JA
7824<DT><B>isearch-terminators (``C-[C-J'')</B>
7825
7826<DD>
7827The string of characters that should terminate an incremental
7828search without subsequently executing the character as a command.
7829If this variable has not been given a value, the characters
7830<I>ESC</I> and <I>C-J</I> will terminate an incremental search.
7831<DT><B>keymap (emacs)</B>
7832
7833<DD>
7834Set the current readline keymap. The set of valid keymap names is
7835<I>emacs, emacs-standard, emacs-meta, emacs-ctlx, vi,
7836vi-command</I>, and
7837<I>vi-insert</I>.
7838
7839<I>vi</I> is equivalent to <I>vi-command</I>; <I>emacs</I> is
7840equivalent to <I>emacs-standard</I>. The default value is
7841<I>emacs</I>;
7842
7843the value of
7844<B>editing-mode</B>
7845
7846also affects the default keymap.
ac50fbac
CR
7847<DT><B>keyseq-timeout (500)</B>
7848
7849<DD>
7850Specifies the duration <I>readline</I> will wait for a character when reading an
7851ambiguous key sequence (one that can form a complete key sequence using
7852the input read so far, or can take additional input to complete a longer
7853key sequence).
7854If no input is received within the timeout, <I>readline</I> will use the shorter
7855but complete key sequence.
7856The value is specified in milliseconds, so a value of 1000 means that
7857<I>readline</I> will wait one second for additional input.
7858If this variable is set to a value less than or equal to zero, or to a
7859non-numeric value, <I>readline</I> will wait until another key is pressed to
7860decide which key sequence to complete.
17345e5a
JA
7861<DT><B>mark-directories (On)</B>
7862
7863<DD>
7864If set to <B>On</B>, completed directory names have a slash
7865appended.
7866<DT><B>mark-modified-lines (Off)</B>
7867
7868<DD>
7869If set to <B>On</B>, history lines that have been modified are displayed
7870with a preceding asterisk (<B>*</B>).
7871<DT><B>mark-symlinked-directories (Off)</B>
7872
7873<DD>
7874If set to <B>On</B>, completed names which are symbolic links to directories
7875have a slash appended (subject to the value of
7876<B>mark-directories</B>).
7877<DT><B>match-hidden-files (On)</B>
7878
7879<DD>
7880This variable, when set to <B>On</B>, causes readline to match files whose
a0c0a00f 7881names begin with a `.' (hidden files) when performing filename
495aee44
CR
7882completion.
7883If set to <B>Off</B>, the leading `.' must be
17345e5a 7884supplied by the user in the filename to be completed.
495aee44
CR
7885<DT><B>menu-complete-display-prefix (Off)</B>
7886
7887<DD>
7888If set to <B>On</B>, menu completion displays the common prefix of the
7889list of possible completions (which may be empty) before cycling through
7890the list.
17345e5a
JA
7891<DT><B>output-meta (Off)</B>
7892
7893<DD>
7894If set to <B>On</B>, readline will display characters with the
7895eighth bit set directly rather than as a meta-prefixed escape
7896sequence.
a0c0a00f
CR
7897The default is <I>Off</I>, but readline will set it to <I>On</I> if the
7898locale contains eight-bit characters.
74091dd4
CR
7899This variable is dependent on the <B>LC_CTYPE</B> locale category, and
7900may change if the locale is changed.
17345e5a
JA
7901<DT><B>page-completions (On)</B>
7902
7903<DD>
7904If set to <B>On</B>, readline uses an internal <I>more</I>-like pager
7905to display a screenful of possible completions at a time.
7906<DT><B>print-completions-horizontally (Off)</B>
7907
7908<DD>
7909If set to <B>On</B>, readline will display completions with matches
7910sorted horizontally in alphabetical order, rather than down the screen.
7911<DT><B>revert-all-at-newline (Off)</B>
7912
7913<DD>
a0c0a00f 7914If set to <B>On</B>, readline will undo all changes to history lines
17345e5a
JA
7915before returning when <B>accept-line</B> is executed. By default,
7916history lines may be modified and retain individual undo lists across
7917calls to <B>readline</B>.
7918<DT><B>show-all-if-ambiguous (Off)</B>
7919
7920<DD>
7921This alters the default behavior of the completion functions. If
7922set to
495aee44 7923<B>On</B>,
17345e5a
JA
7924
7925words which have more than one possible completion cause the
7926matches to be listed immediately instead of ringing the bell.
7927<DT><B>show-all-if-unmodified (Off)</B>
7928
7929<DD>
7930This alters the default behavior of the completion functions in
7931a fashion similar to <B>show-all-if-ambiguous</B>.
7932If set to
495aee44 7933<B>On</B>,
17345e5a
JA
7934
7935words which have more than one possible completion without any
7936possible partial completion (the possible completions don't share
7937a common prefix) cause the matches to be listed immediately instead
7938of ringing the bell.
ac50fbac
CR
7939<DT><B>show-mode-in-prompt (Off)</B>
7940
7941<DD>
d233b485
CR
7942If set to <B>On</B>, add a string to the beginning of the prompt
7943indicating the editing mode: emacs, vi command, or vi insertion.
7944The mode strings are user-settable (e.g., <I>emacs-mode-string</I>).
0001803f
CR
7945<DT><B>skip-completed-text (Off)</B>
7946
7947<DD>
7948If set to <B>On</B>, this alters the default completion behavior when
7949inserting a single match into the line. It's only active when
7950performing completion in the middle of a word. If enabled, readline
7951does not insert characters from the completion that match characters
7952after point in the word being completed, so portions of the word
7953following the cursor are not duplicated.
a0c0a00f
CR
7954<DT><B>vi-cmd-mode-string ((cmd))</B>
7955
7956<DD>
d233b485
CR
7957If the <I>show-mode-in-prompt</I> variable is enabled,
7958this string is displayed immediately before the last line of the primary
a0c0a00f
CR
7959prompt when vi editing mode is active and in command mode.
7960The value is expanded like a
7961key binding, so the standard set of meta- and control prefixes and
7962backslash escape sequences is available.
7963Use the \1 and \2 escapes to begin and end sequences of
7964non-printing characters, which can be used to embed a terminal control
7965sequence into the mode string.
7966<DT><B>vi-ins-mode-string ((ins))</B>
7967
7968<DD>
d233b485
CR
7969If the <I>show-mode-in-prompt</I> variable is enabled,
7970this string is displayed immediately before the last line of the primary
a0c0a00f
CR
7971prompt when vi editing mode is active and in insertion mode.
7972The value is expanded like a
7973key binding, so the standard set of meta- and control prefixes and
7974backslash escape sequences is available.
7975Use the \1 and \2 escapes to begin and end sequences of
7976non-printing characters, which can be used to embed a terminal control
7977sequence into the mode string.
17345e5a
JA
7978<DT><B>visible-stats (Off)</B>
7979
7980<DD>
7981If set to <B>On</B>, a character denoting a file's type as reported
7982by <I>stat</I>(2) is appended to the filename when listing possible
7983completions.
7984
7985</DL>
7986<A NAME="lbCK">&nbsp;</A>
7987<H4>Readline Conditional Constructs</H4>
7988
17345e5a
JA
7989Readline implements a facility similar in spirit to the conditional
7990compilation features of the C preprocessor which allows key
7991bindings and variable settings to be performed as the result
7992of tests. There are four parser directives used.
7993<DL COMPACT>
7994<DT><B>$if</B><DD>
a0c0a00f 7995The
17345e5a
JA
7996<B>$if</B>
7997
7998construct allows bindings to be made based on the
7999editing mode, the terminal being used, or the application using
d233b485
CR
8000readline. The text of the test, after any comparison operator,
8001<BR>&nbsp;extends&nbsp;to&nbsp;the&nbsp;end&nbsp;of&nbsp;the&nbsp;line;
8002unless otherwise noted, no characters are required to isolate it.
17345e5a
JA
8003<DL COMPACT><DT><DD>
8004<DL COMPACT>
8005<DT><B>mode</B><DD>
8006The <B>mode=</B> form of the <B>$if</B> directive is used to test
8007whether readline is in emacs or vi mode.
8008This may be used in conjunction
8009with the <B>set keymap</B> command, for instance, to set bindings in
8010the <I>emacs-standard</I> and <I>emacs-ctlx</I> keymaps only if
8011readline is starting out in emacs mode.
8012<DT><B>term</B><DD>
8013The <B>term=</B> form may be used to include terminal-specific
8014key bindings, perhaps to bind the key sequences output by the
8015terminal's function keys. The word on the right side of the
8016<B>=</B>
8017
a0c0a00f 8018is tested against both the full name of the terminal and the portion
17345e5a
JA
8019of the terminal name before the first <B>-</B>. This allows
8020<I>sun</I>
8021
8022to match both
8023<I>sun</I>
8024
8025and
8026<I>sun-cmd</I>,
8027
8028for instance.
d233b485
CR
8029<DT><B>version</B><DD>
8030The <B>version</B> test may be used to perform comparisons against
8031specific readline versions.
8032The <B>version</B> expands to the current readline version.
8033The set of comparison operators includes
8034<B>=</B>,
8035
8036(and
8037<B>==</B>),
8038
8039<B>!=</B>,
8040
8041<B>&lt;=</B>,
8042
8043<B>&gt;=</B>,
8044
8045<B>&lt;</B>,
8046
8047and
8048<B>&gt;</B>.
8049
8050The version number supplied on the right side of the operator consists
8051of a major version number, an optional decimal point, and an optional
8052minor version (e.g., <B>7.1</B>). If the minor version is omitted, it
8053is assumed to be <B>0</B>.
8868edaf 8054The operator may be separated from the string <B>version</B>
d233b485 8055and from the version number argument by whitespace.
17345e5a
JA
8056<DT><B>application</B><DD>
8057The <B>application</B> construct is used to include
8058application-specific settings. Each program using the readline
8059library sets the <I>application name</I>, and an initialization
8060file can test for a particular value.
8061This could be used to bind key sequences to functions useful for
8062a specific program. For instance, the following command adds a
495aee44 8063key sequence that quotes the current or previous word in <B>bash</B>:
17345e5a
JA
8064<P>
8065<DL COMPACT><DT><DD>
8066<PRE>
8067<B>$if</B> Bash
8068# Quote the current or previous word
8069&quot;\C-xq&quot;: &quot;\eb\&quot;\ef\&quot;&quot;
8070<B>$endif</B>
8071</PRE>
8072
8073</DL>
8074
d233b485
CR
8075<DT><I>variable</I><DD>
8076The <I>variable</I> construct provides simple equality tests for readline
8077variables and values.
8078The permitted comparison operators are <I>=</I>, <I>==</I>, and <I>!=</I>.
8079The variable name must be separated from the comparison operator by
8080whitespace; the operator may be separated from the value on the right hand
8081side by whitespace.
8082Both string and boolean variables may be tested. Boolean variables must be
8083tested against the values <I>on</I> and <I>off</I>.
17345e5a
JA
8084</DL></DL>
8085
8086<DT><B>$endif</B><DD>
8087This command, as seen in the previous example, terminates an
8088<B>$if</B> command.
8089<DT><B>$else</B><DD>
8090Commands in this branch of the <B>$if</B> directive are executed if
8091the test fails.
8092<DT><B>$include</B><DD>
8093This directive takes a single filename as an argument and reads commands
8094and bindings from that file. For example, the following directive
8095would read <A HREF="file:/etc/inputrc"><I>/etc/inputrc</I></A>:
8096<P>
8097<DL COMPACT><DT><DD>
8098<PRE>
8099<B>$include</B> <A HREF="file:/etc/inputrc"><I>/etc/inputrc</I></A>
8100</PRE>
8101
8102</DL>
8103
8104</DL>
8105<A NAME="lbCL">&nbsp;</A>
8106<H4>Searching</H4>
8107
17345e5a
JA
8108Readline provides commands for searching through the command history
8109(see
8110<FONT SIZE=-1><B>HISTORY</B>
8111
8112</FONT>
8113below) for lines containing a specified string.
8114There are two search modes:
8115<I>incremental</I>
8116
8117and
8118<I>non-incremental</I>.
8119
8120<P>
8121
8122Incremental searches begin before the user has finished typing the
8123search string.
8124As each character of the search string is typed, readline displays
8125the next entry from the history matching the string typed so far.
8126An incremental search requires only as many characters as needed to
8127find the desired history entry.
8128The characters present in the value of the <B>isearch-terminators</B>
8129variable are used to terminate an incremental search.
8130If that variable has not been assigned a value the Escape and
8131Control-J characters will terminate an incremental search.
8132Control-G will abort an incremental search and restore the original
8133line.
8134When the search is terminated, the history entry containing the
8135search string becomes the current line.
8136<P>
8137
8138To find other matching entries in the history list, type Control-S or
8139Control-R as appropriate.
8140This will search backward or forward in the history for the next
8141entry matching the search string typed so far.
8142Any other key sequence bound to a readline command will terminate
8143the search and execute that command.
8144For instance, a <I>newline</I> will terminate the search and accept
8145the line, thereby executing the command from the history list.
8146<P>
8147
8148Readline remembers the last incremental search string. If two
8149Control-Rs are typed without any intervening characters defining a
8150new search string, any remembered search string is used.
8151<P>
8152
8153Non-incremental searches read the entire search string before starting
8154to search for matching history lines. The search string may be
8155typed by the user or be part of the contents of the current line.
8156<A NAME="lbCM">&nbsp;</A>
8157<H4>Readline Command Names</H4>
8158
17345e5a
JA
8159The following is a list of the names of the commands and the default
8160key sequences to which they are bound.
8161Command names without an accompanying key sequence are unbound by default.
8162In the following descriptions, <I>point</I> refers to the current cursor
8163position, and <I>mark</I> refers to a cursor position saved by the
8164<B>set-mark</B> command.
8165The text between the point and mark is referred to as the <I>region</I>.
8166<A NAME="lbCN">&nbsp;</A>
8167<H4>Commands for Moving</H4>
8168
17345e5a
JA
8169
8170<DL COMPACT>
8171<DT><B>beginning-of-line (C-a)</B>
8172
8173<DD>
8174Move to the start of the current line.
8175<DT><B>end-of-line (C-e)</B>
8176
8177<DD>
8178Move to the end of the line.
8179<DT><B>forward-char (C-f)</B>
8180
8181<DD>
8182Move forward a character.
8183<DT><B>backward-char (C-b)</B>
8184
8185<DD>
8186Move back a character.
8187<DT><B>forward-word (M-f)</B>
8188
8189<DD>
8190Move forward to the end of the next word. Words are composed of
8191alphanumeric characters (letters and digits).
8192<DT><B>backward-word (M-b)</B>
8193
8194<DD>
8195Move back to the start of the current or previous word.
8196Words are composed of alphanumeric characters (letters and digits).
8197<DT><B>shell-forward-word</B>
8198
8199<DD>
8200Move forward to the end of the next word.
8201Words are delimited by non-quoted shell metacharacters.
8202<DT><B>shell-backward-word</B>
8203
8204<DD>
8205Move back to the start of the current or previous word.
8206Words are delimited by non-quoted shell metacharacters.
d233b485
CR
8207<DT><B>previous-screen-line</B>
8208
8209<DD>
8210Attempt to move point to the same physical screen column on the previous
8211physical screen line. This will not have the desired effect if the current
74091dd4 8212readline line does not take up more than one physical line or if point is not
d233b485
CR
8213greater than the length of the prompt plus the screen width.
8214<DT><B>next-screen-line</B>
8215
8216<DD>
8217Attempt to move point to the same physical screen column on the next
8218physical screen line. This will not have the desired effect if the current
74091dd4
CR
8219readline line does not take up more than one physical line or if the length
8220of the current readline line is not greater than the length of the prompt
d233b485 8221plus the screen width.
8868edaf
CR
8222<DT><B>clear-display (M-C-l)</B>
8223
8224<DD>
8225Clear the screen and, if possible, the terminal's scrollback buffer,
8226then redraw the current line,
8227leaving the current line at the top of the screen.
17345e5a
JA
8228<DT><B>clear-screen (C-l)</B>
8229
8230<DD>
8868edaf
CR
8231Clear the screen,
8232then redraw the current line,
8233leaving the current line at the top of the screen.
17345e5a
JA
8234With an argument, refresh the current line without clearing the
8235screen.
8236<DT><B>redraw-current-line</B>
8237
8238<DD>
8239Refresh the current line.
8240
8241</DL>
8242<A NAME="lbCO">&nbsp;</A>
8243<H4>Commands for Manipulating the History</H4>
8244
17345e5a
JA
8245
8246<DL COMPACT>
8247<DT><B>accept-line (Newline, Return)</B>
8248
8249<DD>
8250Accept the line regardless of where the cursor is. If this line is
8251non-empty, add it to the history list according to the state of the
8252<FONT SIZE=-1><B>HISTCONTROL</B>
8253
8254</FONT>
8255variable. If the line is a modified history
8256line, then restore the history line to its original state.
8257<DT><B>previous-history (C-p)</B>
8258
8259<DD>
8260Fetch the previous command from the history list, moving back in
8261the list.
8262<DT><B>next-history (C-n)</B>
8263
8264<DD>
8265Fetch the next command from the history list, moving forward in the
8266list.
8267<DT><B>beginning-of-history (M-&lt;)</B>
8268
8269<DD>
8270Move to the first line in the history.
8271<DT><B>end-of-history (M-&gt;)</B>
8272
8273<DD>
8274Move to the end of the input history, i.e., the line currently being
8275entered.
74091dd4
CR
8276<DT><B>operate-and-get-next (C-o)</B>
8277
8278<DD>
8279Accept the current line for execution and fetch the next line
8280relative to the current line from the history for editing.
8281A numeric argument, if supplied, specifies the history entry to use instead
8282of the current line.
8283<DT><B>fetch-history</B>
8284
8285<DD>
8286With a numeric argument, fetch that entry from the history list
8287and make it the current line.
8288Without an argument, move back to the first entry in the history list.
17345e5a
JA
8289<DT><B>reverse-search-history (C-r)</B>
8290
8291<DD>
8292Search backward starting at the current line and moving `up' through
8293the history as necessary. This is an incremental search.
8294<DT><B>forward-search-history (C-s)</B>
8295
8296<DD>
8297Search forward starting at the current line and moving `down' through
8298the history as necessary. This is an incremental search.
8299<DT><B>non-incremental-reverse-search-history (M-p)</B>
8300
8301<DD>
8302Search backward through the history starting at the current line
8303using a non-incremental search for a string supplied by the user.
8304<DT><B>non-incremental-forward-search-history (M-n)</B>
8305
8306<DD>
8307Search forward through the history using a non-incremental search for
8308a string supplied by the user.
8309<DT><B>history-search-forward</B>
8310
8311<DD>
8312Search forward through the history for the string of characters
8313between the start of the current line and the point.
8314This is a non-incremental search.
8315<DT><B>history-search-backward</B>
8316
8317<DD>
8318Search backward through the history for the string of characters
8319between the start of the current line and the point.
8320This is a non-incremental search.
d233b485
CR
8321<DT><B>history-substring-search-backward</B>
8322
8323<DD>
8868edaf 8324Search backward through the history for the string of characters
d233b485
CR
8325between the start of the current line and the current cursor
8326position (the <I>point</I>).
8327The search string may match anywhere in a history line.
8328This is a non-incremental search.
8329<DT><B>history-substring-search-forward</B>
8330
8331<DD>
8332Search forward through the history for the string of characters
8333between the start of the current line and the point.
8334The search string may match anywhere in a history line.
8335This is a non-incremental search.
17345e5a
JA
8336<DT><B>yank-nth-arg (M-C-y)</B>
8337
8338<DD>
8339Insert the first argument to the previous command (usually
8340the second word on the previous line) at point.
8341With an argument
8342<I>n</I>,
8343
8344insert the <I>n</I>th word from the previous command (the words
8345in the previous command begin with word 0). A negative argument
8346inserts the <I>n</I>th word from the end of the previous command.
8347Once the argument <I>n</I> is computed, the argument is extracted
8348as if the &quot;!<I>n</I>&quot; history expansion had been specified.
8349<DT><B>yank-last-arg (M-., M-_)</B>
8350
8351<DD>
8352Insert the last argument to the previous command (the last word of
495aee44
CR
8353the previous history entry).
8354With a numeric argument, behave exactly like <B>yank-nth-arg</B>.
17345e5a 8355Successive calls to <B>yank-last-arg</B> move back through the history
495aee44
CR
8356list, inserting the last word (or the word specified by the argument to
8357the first call) of each line in turn.
8358Any numeric argument supplied to these successive calls determines
8359the direction to move through the history. A negative argument switches
8360the direction through the history (back or forward).
ac50fbac 8361The history expansion facilities are used to extract the last word,
17345e5a
JA
8362as if the &quot;!$&quot; history expansion had been specified.
8363<DT><B>shell-expand-line (M-C-e)</B>
8364
8365<DD>
8366Expand the line as the shell does. This
8367performs alias and history expansion as well as all of the shell
8368word expansions. See
8369<FONT SIZE=-1><B>HISTORY EXPANSION</B>
8370
8371</FONT>
8372below for a description of history expansion.
8373<DT><B>history-expand-line (M-^)</B>
8374
8375<DD>
8376Perform history expansion on the current line.
8377See
8378<FONT SIZE=-1><B>HISTORY EXPANSION</B>
8379
8380</FONT>
8381below for a description of history expansion.
8382<DT><B>magic-space</B>
8383
8384<DD>
8385Perform history expansion on the current line and insert a space.
8386See
8387<FONT SIZE=-1><B>HISTORY EXPANSION</B>
8388
8389</FONT>
8390below for a description of history expansion.
8391<DT><B>alias-expand-line</B>
8392
8393<DD>
8394Perform alias expansion on the current line.
8395See
8396<FONT SIZE=-1><B>ALIASES</B>
8397
8398</FONT>
8399above for a description of alias expansion.
8400<DT><B>history-and-alias-expand-line</B>
8401
8402<DD>
8403Perform history and alias expansion on the current line.
8404<DT><B>insert-last-argument (M-., M-_)</B>
8405
8406<DD>
8407A synonym for <B>yank-last-arg</B>.
d233b485 8408<DT><B>edit-and-execute-command (C-x C-e)</B>
17345e5a
JA
8409
8410<DD>
8411Invoke an editor on the current command line, and execute the result as shell
8412commands.
8413<B>Bash</B> attempts to invoke
8414<FONT SIZE=-1><B>$VISUAL</B>,
8415
8416</FONT>
8417<FONT SIZE=-1><B>$EDITOR</B>,
8418
8419</FONT>
8420and <I>emacs</I> as the editor, in that order.
8421
8422</DL>
8423<A NAME="lbCP">&nbsp;</A>
8424<H4>Commands for Changing Text</H4>
8425
17345e5a
JA
8426
8427<DL COMPACT>
ac50fbac 8428<DT><B></B><I>end-of-file</I> (usually C-d)
17345e5a
JA
8429
8430<DD>
ac50fbac
CR
8431The character indicating end-of-file as set, for example, by
8432<TT>stty</TT>.
8433
8434If this character is read when there are no characters
74091dd4 8435on the line, and point is at the beginning of the line, readline
ac50fbac 8436interprets it as the end of input and returns
17345e5a
JA
8437<FONT SIZE=-1><B>EOF</B>.
8438
8439</FONT>
ac50fbac
CR
8440<DT><B>delete-char (C-d)</B>
8441
8442<DD>
8443Delete the character at point.
8444If this function is bound to the
8445same character as the tty <B>EOF</B> character, as <B>C-d</B>
8446commonly is, see above for the effects.
17345e5a
JA
8447<DT><B>backward-delete-char (Rubout)</B>
8448
8449<DD>
8450Delete the character behind the cursor. When given a numeric argument,
8451save the deleted text on the kill ring.
8452<DT><B>forward-backward-delete-char</B>
8453
8454<DD>
8455Delete the character under the cursor, unless the cursor is at the
8456end of the line, in which case the character behind the cursor is
8457deleted.
8458<DT><B>quoted-insert (C-q, C-v)</B>
8459
8460<DD>
8461Add the next character typed to the line verbatim. This is
8462how to insert characters like <B>C-q</B>, for example.
8463<DT><B>tab-insert (C-v TAB)</B>
8464
8465<DD>
8466Insert a tab character.
8467<DT><B>self-insert (a,&nbsp;b,&nbsp;A,&nbsp;1,&nbsp;!,&nbsp;...)</B>
8468
8469<DD>
8470Insert the character typed.
8471<DT><B>transpose-chars (C-t)</B>
8472
8473<DD>
8474Drag the character before point forward over the character at point,
8475moving point forward as well.
8476If point is at the end of the line, then this transposes
8477the two characters before point.
8478Negative arguments have no effect.
8479<DT><B>transpose-words (M-t)</B>
8480
8481<DD>
8482Drag the word before point past the word after point,
8483moving point over that word as well.
8484If point is at the end of the line, this transposes
a0c0a00f 8485the last two words on the line.
17345e5a
JA
8486<DT><B>upcase-word (M-u)</B>
8487
8488<DD>
8489Uppercase the current (or following) word. With a negative argument,
8490uppercase the previous word, but do not move point.
8491<DT><B>downcase-word (M-l)</B>
8492
8493<DD>
8494Lowercase the current (or following) word. With a negative argument,
8495lowercase the previous word, but do not move point.
8496<DT><B>capitalize-word (M-c)</B>
8497
8498<DD>
8499Capitalize the current (or following) word. With a negative argument,
8500capitalize the previous word, but do not move point.
8501<DT><B>overwrite-mode</B>
8502
8503<DD>
8504Toggle overwrite mode. With an explicit positive numeric argument,
8505switches to overwrite mode. With an explicit non-positive numeric
8506argument, switches to insert mode. This command affects only
8507<B>emacs</B> mode; <B>vi</B> mode does overwrite differently.
8508Each call to <I>readline()</I> starts in insert mode.
a0c0a00f 8509In overwrite mode, characters bound to <B>self-insert</B> replace
17345e5a
JA
8510the text at point rather than pushing the text to the right.
8511Characters bound to <B>backward-delete-char</B> replace the character
8512before point with a space. By default, this command is unbound.
8513
8514</DL>
8515<A NAME="lbCQ">&nbsp;</A>
8516<H4>Killing and Yanking</H4>
8517
17345e5a
JA
8518
8519<DL COMPACT>
8520<DT><B>kill-line (C-k)</B>
8521
8522<DD>
8523Kill the text from point to the end of the line.
8524<DT><B>backward-kill-line (C-x Rubout)</B>
8525
8526<DD>
8527Kill backward to the beginning of the line.
8528<DT><B>unix-line-discard (C-u)</B>
8529
8530<DD>
8531Kill backward from point to the beginning of the line.
8532The killed text is saved on the kill-ring.
8533
8534<DT><B>kill-whole-line</B>
8535
8536<DD>
8537Kill all characters on the current line, no matter where point is.
a0c0a00f 8538<DT><B>kill-word (M-d)</B>
17345e5a
JA
8539
8540<DD>
8541Kill from point to the end of the current word, or if between
8542words, to the end of the next word.
8543Word boundaries are the same as those used by <B>forward-word</B>.
8544<DT><B>backward-kill-word (M-Rubout)</B>
8545
8546<DD>
8547Kill the word behind point.
8548Word boundaries are the same as those used by <B>backward-word</B>.
a0c0a00f 8549<DT><B>shell-kill-word</B>
17345e5a
JA
8550
8551<DD>
8552Kill from point to the end of the current word, or if between
8553words, to the end of the next word.
8554Word boundaries are the same as those used by <B>shell-forward-word</B>.
a0c0a00f 8555<DT><B>shell-backward-kill-word</B>
17345e5a
JA
8556
8557<DD>
8558Kill the word behind point.
8559Word boundaries are the same as those used by <B>shell-backward-word</B>.
8560<DT><B>unix-word-rubout (C-w)</B>
8561
8562<DD>
8563Kill the word behind point, using white space as a word boundary.
8564The killed text is saved on the kill-ring.
8565<DT><B>unix-filename-rubout</B>
8566
8567<DD>
8568Kill the word behind point, using white space and the slash character
8569as the word boundaries.
8570The killed text is saved on the kill-ring.
8571<DT><B>delete-horizontal-space (M-\)</B>
8572
8573<DD>
8574Delete all spaces and tabs around point.
8575<DT><B>kill-region</B>
8576
8577<DD>
8578Kill the text in the current region.
8579<DT><B>copy-region-as-kill</B>
8580
8581<DD>
8582Copy the text in the region to the kill buffer.
8583<DT><B>copy-backward-word</B>
8584
8585<DD>
8586Copy the word before point to the kill buffer.
8587The word boundaries are the same as <B>backward-word</B>.
8588<DT><B>copy-forward-word</B>
8589
8590<DD>
8591Copy the word following point to the kill buffer.
8592The word boundaries are the same as <B>forward-word</B>.
8593<DT><B>yank (C-y)</B>
8594
8595<DD>
8596Yank the top of the kill ring into the buffer at point.
8597<DT><B>yank-pop (M-y)</B>
8598
8599<DD>
8600Rotate the kill ring, and yank the new top. Only works following
8601<B>yank</B>
8602
8603or
8604<B>yank-pop</B>.
8605
8606
8607</DL>
8608<A NAME="lbCR">&nbsp;</A>
8609<H4>Numeric Arguments</H4>
8610
17345e5a
JA
8611
8612<DL COMPACT>
8613<DT><B>digit-argument (M-0, M-1, ..., M--)</B>
8614
8615<DD>
8616Add this digit to the argument already accumulating, or start a new
8617argument. M-- starts a negative argument.
8618<DT><B>universal-argument</B>
8619
8620<DD>
8621This is another way to specify an argument.
8622If this command is followed by one or more digits, optionally with a
8623leading minus sign, those digits define the argument.
8624If the command is followed by digits, executing
8625<B>universal-argument</B>
8626
8627again ends the numeric argument, but is otherwise ignored.
8628As a special case, if this command is immediately followed by a
a0c0a00f 8629character that is neither a digit nor minus sign, the argument count
17345e5a
JA
8630for the next command is multiplied by four.
8631The argument count is initially one, so executing this function the
8632first time makes the argument count four, a second time makes the
8633argument count sixteen, and so on.
8634
8635</DL>
8636<A NAME="lbCS">&nbsp;</A>
8637<H4>Completing</H4>
8638
17345e5a
JA
8639
8640<DL COMPACT>
8641<DT><B>complete (TAB)</B>
8642
8643<DD>
8644Attempt to perform completion on the text before point.
8645<B>Bash</B>
8646
8647attempts completion treating the text as a variable (if the
8648text begins with <B>$</B>), username (if the text begins with
8649<B>~</B>), hostname (if the text begins with <B>@</B>), or
8650command (including aliases and functions) in turn. If none
8651of these produces a match, filename completion is attempted.
8652<DT><B>possible-completions (M-?)</B>
8653
8654<DD>
8655List the possible completions of the text before point.
8656<DT><B>insert-completions (M-*)</B>
8657
8658<DD>
8659Insert all completions of the text before point
8660that would have been generated by
8661<B>possible-completions</B>.
8662<DT><B>menu-complete</B>
8663
8664<DD>
8665Similar to <B>complete</B>, but replaces the word to be completed
8666with a single match from the list of possible completions.
8667Repeated execution of <B>menu-complete</B> steps through the list
8668of possible completions, inserting each match in turn.
8669At the end of the list of completions, the bell is rung
8670(subject to the setting of <B>bell-style</B>)
8671and the original text is restored.
8672An argument of <I>n</I> moves <I>n</I> positions forward in the list
8673of matches; a negative argument may be used to move backward
8674through the list.
8675This command is intended to be bound to <B>TAB</B>, but is unbound
8676by default.
495aee44 8677<DT><B>menu-complete-backward</B>
0001803f
CR
8678
8679<DD>
8680Identical to <B>menu-complete</B>, but moves backward through the list
8681of possible completions, as if <B>menu-complete</B> had been given a
8682negative argument. This command is unbound by default.
17345e5a
JA
8683<DT><B>delete-char-or-list</B>
8684
8685<DD>
8686Deletes the character under the cursor if not at the beginning or
8687end of the line (like <B>delete-char</B>).
8688If at the end of the line, behaves identically to
8689<B>possible-completions</B>.
8690This command is unbound by default.
8691<DT><B>complete-filename (M-/)</B>
8692
8693<DD>
8694Attempt filename completion on the text before point.
8695<DT><B>possible-filename-completions (C-x /)</B>
8696
8697<DD>
8698List the possible completions of the text before point,
8699treating it as a filename.
8700<DT><B>complete-username (M-~)</B>
8701
8702<DD>
8703Attempt completion on the text before point, treating
8704it as a username.
8705<DT><B>possible-username-completions (C-x ~)</B>
8706
8707<DD>
8708List the possible completions of the text before point,
8709treating it as a username.
8710<DT><B>complete-variable (M-$)</B>
8711
8712<DD>
8713Attempt completion on the text before point, treating
8714it as a shell variable.
8715<DT><B>possible-variable-completions (C-x $)</B>
8716
8717<DD>
8718List the possible completions of the text before point,
8719treating it as a shell variable.
8720<DT><B>complete-hostname (M-@)</B>
8721
8722<DD>
8723Attempt completion on the text before point, treating
8724it as a hostname.
8725<DT><B>possible-hostname-completions (C-x @)</B>
8726
8727<DD>
8728List the possible completions of the text before point,
8729treating it as a hostname.
8730<DT><B>complete-command (M-!)</B>
8731
8732<DD>
8733Attempt completion on the text before point, treating
8734it as a command name. Command completion attempts to
8735match the text against aliases, reserved words, shell
8736functions, shell builtins, and finally executable filenames,
8737in that order.
8738<DT><B>possible-command-completions (C-x !)</B>
8739
8740<DD>
8741List the possible completions of the text before point,
8742treating it as a command name.
8743<DT><B>dynamic-complete-history (M-TAB)</B>
8744
8745<DD>
8746Attempt completion on the text before point, comparing
8747the text against lines from the history list for possible
8748completion matches.
8749<DT><B>dabbrev-expand</B>
8750
8751<DD>
8752Attempt menu completion on the text before point, comparing
8753the text against lines from the history list for possible
8754completion matches.
8755<DT><B>complete-into-braces (M-{)</B>
8756
8757<DD>
8758Perform filename completion and insert the list of possible completions
8759enclosed within braces so the list is available to the shell (see
8760<B>Brace Expansion</B>
8761
8762above).
8763
8764</DL>
8765<A NAME="lbCT">&nbsp;</A>
8766<H4>Keyboard Macros</H4>
8767
17345e5a
JA
8768
8769<DL COMPACT>
8770<DT><B>start-kbd-macro (C-x ()</B>
8771
8772<DD>
8773Begin saving the characters typed into the current keyboard macro.
8774<DT><B>end-kbd-macro (C-x ))</B>
8775
8776<DD>
8777Stop saving the characters typed into the current keyboard macro
8778and store the definition.
8779<DT><B>call-last-kbd-macro (C-x e)</B>
8780
8781<DD>
8782Re-execute the last keyboard macro defined, by making the characters
8783in the macro appear as if typed at the keyboard.
ac50fbac
CR
8784<DT><B>print-last-kbd-macro ()</B>
8785
8786<DD>
8787Print the last keyboard macro defined in a format suitable for the
8788<I>inputrc</I> file.
17345e5a
JA
8789
8790</DL>
8791<A NAME="lbCU">&nbsp;</A>
8792<H4>Miscellaneous</H4>
8793
17345e5a
JA
8794
8795<DL COMPACT>
8796<DT><B>re-read-init-file (C-x C-r)</B>
8797
8798<DD>
8799Read in the contents of the <I>inputrc</I> file, and incorporate
8800any bindings or variable assignments found there.
8801<DT><B>abort (C-g)</B>
8802
8803<DD>
8804Abort the current editing command and
8805ring the terminal's bell (subject to the setting of
8806<B>bell-style</B>).
8807
d233b485 8808<DT><B>do-lowercase-version (M-A, M-B, M-</B><I>x</I>, ...)
17345e5a
JA
8809
8810<DD>
d233b485 8811If the metafied character <I>x</I> is uppercase, run the command
8868edaf
CR
8812that is bound to the corresponding metafied lowercase character.
8813The behavior is undefined if <I>x</I> is already lowercase.
17345e5a
JA
8814<DT><B>prefix-meta (ESC)</B>
8815
8816<DD>
8817Metafy the next character typed.
8818<FONT SIZE=-1><B>ESC</B>
8819
8820</FONT>
8821<B>f</B>
8822
8823is equivalent to
8824<B>Meta-f</B>.
8825
8826<DT><B>undo (C-_, C-x C-u)</B>
8827
8828<DD>
8829Incremental undo, separately remembered for each line.
8830<DT><B>revert-line (M-r)</B>
8831
8832<DD>
8833Undo all changes made to this line. This is like executing the
8834<B>undo</B>
8835
8836command enough times to return the line to its initial state.
8837<DT><B>tilde-expand (M-&amp;)</B>
8838
8839<DD>
8840Perform tilde expansion on the current word.
8841<DT><B>set-mark (C-@, M-&lt;space&gt;)</B>
8842
8843<DD>
8844Set the mark to the point. If a
8845numeric argument is supplied, the mark is set to that position.
8846<DT><B>exchange-point-and-mark (C-x C-x)</B>
8847
8848<DD>
8849Swap the point with the mark. The current cursor position is set to
8850the saved position, and the old cursor position is saved as the mark.
8851<DT><B>character-search (C-])</B>
8852
8853<DD>
8854A character is read and point is moved to the next occurrence of that
74091dd4 8855character. A negative argument searches for previous occurrences.
17345e5a
JA
8856<DT><B>character-search-backward (M-C-])</B>
8857
8858<DD>
8859A character is read and point is moved to the previous occurrence of that
74091dd4 8860character. A negative argument searches for subsequent occurrences.
495aee44 8861<DT><B>skip-csi-sequence</B>
0001803f
CR
8862
8863<DD>
8864Read enough characters to consume a multi-key sequence such as those
8865defined for keys like Home and End. Such sequences begin with a
8866Control Sequence Indicator (CSI), usually ESC-[. If this sequence is
8867bound to &quot;\[&quot;, keys producing such sequences will have no effect
8868unless explicitly bound to a readline command, instead of inserting
8869stray characters into the editing buffer. This is unbound by default,
8870but usually bound to ESC-[.
17345e5a
JA
8871<DT><B>insert-comment (M-#)</B>
8872
8873<DD>
8874Without a numeric argument, the value of the readline
8875<B>comment-begin</B>
8876
8877variable is inserted at the beginning of the current line.
a0c0a00f 8878If a numeric argument is supplied, this command acts as a toggle: if
17345e5a
JA
8879the characters at the beginning of the line do not match the value
8880of <B>comment-begin</B>, the value is inserted, otherwise
a0c0a00f 8881the characters in <B>comment-begin</B> are deleted from the beginning of
17345e5a
JA
8882the line.
8883In either case, the line is accepted as if a newline had been typed.
8884The default value of
8885<B>comment-begin</B> causes this command to make the current line
8886a shell comment.
8887If a numeric argument causes the comment character to be removed, the line
8888will be executed by the shell.
74091dd4
CR
8889<DT><B>spell-correct-word (C-x s)</B>
8890
8891<DD>
8892Perform spelling correction on the current word, treating it as a directory
8893or filename, in the same way as the <B>cdspell</B> shell option.
8894Word boundaries are the same as those used by <B>shell-forward-word</B>.
17345e5a
JA
8895<DT><B>glob-complete-word (M-g)</B>
8896
8897<DD>
8898The word before point is treated as a pattern for pathname expansion,
8899with an asterisk implicitly appended. This pattern is used to
ac50fbac 8900generate a list of matching filenames for possible completions.
17345e5a
JA
8901<DT><B>glob-expand-word (C-x *)</B>
8902
8903<DD>
8904The word before point is treated as a pattern for pathname expansion,
ac50fbac 8905and the list of matching filenames is inserted, replacing the word.
17345e5a
JA
8906If a numeric argument is supplied, an asterisk is appended before
8907pathname expansion.
8908<DT><B>glob-list-expansions (C-x g)</B>
8909
8910<DD>
8911The list of expansions that would have been generated by
8912<B>glob-expand-word</B>
8913
8914is displayed, and the line is redrawn.
8915If a numeric argument is supplied, an asterisk is appended before
8916pathname expansion.
8917<DT><B>dump-functions</B>
8918
8919<DD>
8920Print all of the functions and their key bindings to the
8921readline output stream. If a numeric argument is supplied,
8922the output is formatted in such a way that it can be made part
8923of an <I>inputrc</I> file.
8924<DT><B>dump-variables</B>
8925
8926<DD>
8927Print all of the settable readline variables and their values to the
8928readline output stream. If a numeric argument is supplied,
8929the output is formatted in such a way that it can be made part
8930of an <I>inputrc</I> file.
8931<DT><B>dump-macros</B>
8932
8933<DD>
8934Print all of the readline key sequences bound to macros and the
8935strings they output. If a numeric argument is supplied,
8936the output is formatted in such a way that it can be made part
8937of an <I>inputrc</I> file.
8938<DT><B>display-shell-version (C-x C-v)</B>
8939
8940<DD>
8941Display version information about the current instance of
8942<B>bash</B>.
8943
8944
8945</DL>
8946<A NAME="lbCV">&nbsp;</A>
8947<H4>Programmable Completion</H4>
8948
17345e5a
JA
8949When word completion is attempted for an argument to a command for
8950which a completion specification (a <I>compspec</I>) has been defined
8951using the <B>complete</B> builtin (see
8952<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
8953
8954</FONT>
8955below), the programmable completion facilities are invoked.
8956<P>
8957
8958First, the command name is identified.
0001803f
CR
8959If the command word is the empty string (completion attempted at the
8960beginning of an empty line), any compspec defined with
8961the <B>-E</B> option to <B>complete</B> is used.
17345e5a
JA
8962If a compspec has been defined for that command, the
8963compspec is used to generate the list of possible completions for the word.
8964If the command word is a full pathname, a compspec for the full
8965pathname is searched for first.
8966If no compspec is found for the full pathname, an attempt is made to
8967find a compspec for the portion following the final slash.
495aee44 8968If those searches do not result in a compspec, any compspec defined with
0001803f 8969the <B>-D</B> option to <B>complete</B> is used as the default.
d233b485
CR
8970If there is no default compspec, <B>bash</B> attempts alias expansion
8971on the command word as a final resort, and attempts to find a compspec
8972for the command word from any successful expansion.
17345e5a
JA
8973<P>
8974
8975Once a compspec has been found, it is used to generate the list of
8976matching words.
8977If a compspec is not found, the default <B>bash</B> completion as
8978described above under <B>Completing</B> is performed.
8979<P>
8980
8981First, the actions specified by the compspec are used.
8982Only matches which are prefixed by the word being completed are
8983returned.
8984When the
8985<B>-f</B>
8986
8987or
8988<B>-d</B>
8989
8990option is used for filename or directory name completion, the shell
8991variable
8992<FONT SIZE=-1><B>FIGNORE</B>
8993
8994</FONT>
8995is used to filter the matches.
8996<P>
8997
0001803f 8998Any completions specified by a pathname expansion pattern to the
17345e5a
JA
8999<B>-G</B> option are generated next.
9000The words generated by the pattern need not match the word
9001being completed.
9002The
9003<FONT SIZE=-1><B>GLOBIGNORE</B>
9004
9005</FONT>
9006shell variable is not used to filter the matches, but the
9007<FONT SIZE=-1><B>FIGNORE</B>
9008
9009</FONT>
9010variable is used.
9011<P>
9012
9013Next, the string specified as the argument to the <B>-W</B> option
9014is considered.
9015The string is first split using the characters in the
9016<FONT SIZE=-1><B>IFS</B>
9017
9018</FONT>
9019special variable as delimiters.
9020Shell quoting is honored.
9021Each word is then expanded using
9022brace expansion, tilde expansion, parameter and variable expansion,
9023command substitution, and arithmetic expansion,
a0c0a00f 9024as described above under
17345e5a
JA
9025<FONT SIZE=-1><B>EXPANSION</B>.
9026
9027</FONT>
9028The results are split using the rules described above under
9029<B>Word Splitting</B>.
9030The results of the expansion are prefix-matched against the word being
9031completed, and the matching words become the possible completions.
9032<P>
9033
9034After these matches have been generated, any shell function or command
9035specified with the <B>-F</B> and <B>-C</B> options is invoked.
9036When the command or function is invoked, the
9037<FONT SIZE=-1><B>COMP_LINE</B>,
9038
9039</FONT>
9040<FONT SIZE=-1><B>COMP_POINT</B>,
9041
9042</FONT>
9043<FONT SIZE=-1><B>COMP_KEY</B>,
9044
9045</FONT>
9046and
9047<FONT SIZE=-1><B>COMP_TYPE</B>
9048
9049</FONT>
9050variables are assigned values as described above under
9051<B>Shell Variables</B>.
a0c0a00f 9052If a shell function is being invoked, the
17345e5a
JA
9053<FONT SIZE=-1><B>COMP_WORDS</B>
9054
9055</FONT>
9056and
9057<FONT SIZE=-1><B>COMP_CWORD</B>
9058
9059</FONT>
9060variables are also set.
ac50fbac
CR
9061When the function or command is invoked,
9062the first argument (<B>$1</B>) is the name of the command whose arguments are
9063being completed,
9064the second argument (<B>$2</B>) is the word being completed,
9065and the third argument (<B>$3</B>) is the word preceding the word being
9066completed on the current command line.
17345e5a
JA
9067No filtering of the generated completions against the word being completed
9068is performed; the function or command has complete freedom in generating
9069the matches.
9070<P>
9071
9072Any function specified with <B>-F</B> is invoked first.
9073The function may use any of the shell facilities, including the
9074<B>compgen</B> builtin described below, to generate the matches.
9075It must put the possible completions in the
9076<FONT SIZE=-1><B>COMPREPLY</B>
9077
9078</FONT>
ac50fbac 9079array variable, one per array element.
17345e5a
JA
9080<P>
9081
9082Next, any command specified with the <B>-C</B> option is invoked
9083in an environment equivalent to command substitution.
9084It should print a list of completions, one per line, to the
9085standard output.
9086Backslash may be used to escape a newline, if necessary.
9087<P>
9088
9089After all of the possible completions are generated, any filter
9090specified with the <B>-X</B> option is applied to the list.
9091The filter is a pattern as used for pathname expansion; a <B>&amp;</B>
9092in the pattern is replaced with the text of the word being completed.
9093A literal <B>&amp;</B> may be escaped with a backslash; the backslash
9094is removed before attempting a match.
9095Any completion that matches the pattern will be removed from the list.
9096A leading <B>!</B> negates the pattern; in this case any completion
9097not matching the pattern will be removed.
a0c0a00f
CR
9098If the
9099<B>nocasematch</B>
9100
9101shell option is enabled, the match is performed without regard to the case
9102of alphabetic characters.
17345e5a
JA
9103<P>
9104
9105Finally, any prefix and suffix specified with the <B>-P</B> and <B>-S</B>
9106options are added to each member of the completion list, and the result is
9107returned to the readline completion code as the list of possible
9108completions.
9109<P>
9110
9111If the previously-applied actions do not generate any matches, and the
9112<B>-o dirnames</B> option was supplied to <B>complete</B> when the
9113compspec was defined, directory name completion is attempted.
9114<P>
9115
9116If the <B>-o plusdirs</B> option was supplied to <B>complete</B> when the
9117compspec was defined, directory name completion is attempted and any
9118matches are added to the results of the other actions.
9119<P>
9120
9121By default, if a compspec is found, whatever it generates is returned
9122to the completion code as the full set of possible completions.
9123The default <B>bash</B> completions are not attempted, and the readline
9124default of filename completion is disabled.
9125If the <B>-o bashdefault</B> option was supplied to <B>complete</B> when
9126the compspec was defined, the <B>bash</B> default completions are attempted
9127if the compspec generates no matches.
9128If the <B>-o default</B> option was supplied to <B>complete</B> when the
9129compspec was defined, readline's default completion will be performed
9130if the compspec (and, if attempted, the default <B>bash</B> completions)
9131generate no matches.
9132<P>
9133
9134When a compspec indicates that directory name completion is desired,
9135the programmable completion functions force readline to append a slash
a0c0a00f 9136to completed names which are symbolic links to directories, subject to
17345e5a
JA
9137the value of the <B>mark-directories</B> readline variable, regardless
9138of the setting of the <B>mark-symlinked-directories</B> readline variable.
0001803f
CR
9139<P>
9140
9141There is some support for dynamically modifying completions. This is
9142most useful when used in combination with a default completion specified
9143with <B>complete -D</B>.
9144It's possible for shell functions executed as completion
9145handlers to indicate that completion should be retried by returning an
9146exit status of 124. If a shell function returns 124, and changes
9147the compspec associated with the command on which completion is being
9148attempted (supplied as the first argument when the function is executed),
9149programmable completion restarts from the beginning, with an
495aee44 9150attempt to find a new compspec for that command. This allows a set of
0001803f
CR
9151completions to be built dynamically as completion is attempted, rather than
9152being loaded all at once.
9153<P>
9154
9155For instance, assuming that there is a library of compspecs, each kept in a
9156file corresponding to the name of the command, the following default
9157completion function would load completions dynamically:
9158<P>
9159
9160<TT>_completion_loader()
9161<BR>
9162
9163{
9164<BR>
9165
9166<TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TT>. &quot;/etc/bash_completion.d/$1.sh&quot; &gt;/dev/null 2&gt;&amp;1 &amp;&amp; return 124<BR>
9167<BR>
9168
9169}
9170<BR>
9171
ac50fbac 9172complete -D -F _completion_loader -o bashdefault -o default
0001803f
CR
9173<BR>
9174
9175</TT>
17345e5a
JA
9176<A NAME="lbCW">&nbsp;</A>
9177<H3>HISTORY</H3>
9178
9179When the
9180<B>-o history</B>
9181
9182option to the
9183<B>set</B>
9184
9185builtin is enabled, the shell provides access to the
9186<I>command history</I>,
9187the list of commands previously typed.
0001803f
CR
9188The value of the
9189<FONT SIZE=-1><B>HISTSIZE</B>
9190
9191</FONT>
9192variable is used as the
17345e5a
JA
9193number of commands to save in a history list.
9194The text of the last
9195<FONT SIZE=-1><B>HISTSIZE</B>
9196
9197</FONT>
9198commands (default 500) is saved. The shell
9199stores each command in the history list prior to parameter and
9200variable expansion (see
9201<FONT SIZE=-1><B>EXPANSION</B>
9202
9203</FONT>
9204above) but after history expansion is performed, subject to the
9205values of the shell variables
9206<FONT SIZE=-1><B>HISTIGNORE</B>
9207
9208</FONT>
9209and
9210<FONT SIZE=-1><B>HISTCONTROL</B>.
9211
9212</FONT>
9213<P>
9214
9215On startup, the history is initialized from the file named by
9216the variable
9217<FONT SIZE=-1><B>HISTFILE</B>
9218
9219</FONT>
9220(default <A HREF="file:~/.bash_history"><I>~/.bash_history</I></A>).
9221The file named by the value of
9222<FONT SIZE=-1><B>HISTFILE</B>
9223
9224</FONT>
9225is truncated, if necessary, to contain no more than
9226the number of lines specified by the value of
9227<FONT SIZE=-1><B>HISTFILESIZE</B>.
9228
9229</FONT>
ac50fbac
CR
9230If <B>HISTFILESIZE</B> is unset, or set to null, a non-numeric value,
9231or a numeric value less than zero, the history file is not truncated.
17345e5a
JA
9232When the history file is read,
9233lines beginning with the history comment character followed immediately
d233b485 9234by a digit are interpreted as timestamps for the following history line.
17345e5a
JA
9235These timestamps are optionally displayed depending on the value of the
9236<FONT SIZE=-1><B>HISTTIMEFORMAT</B>
9237
9238</FONT>
9239variable.
ac50fbac 9240When a shell with history enabled exits, the last
17345e5a
JA
9241<FONT SIZE=-1><B>$HISTSIZE</B>
9242
9243</FONT>
9244lines are copied from the history list to
9245<FONT SIZE=-1><B>$HISTFILE</B>.
9246
9247</FONT>
9248If the
9249<B>histappend</B>
9250
9251shell option is enabled
9252(see the description of
9253<B>shopt</B>
9254
9255under
9256<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
9257
9258</FONT>
9259below), the lines are appended to the history file,
9260otherwise the history file is overwritten.
9261If
9262<FONT SIZE=-1><B>HISTFILE</B>
9263
9264</FONT>
9265is unset, or if the history file is unwritable, the history is
9266not saved.
9267If the
0001803f
CR
9268<FONT SIZE=-1><B>HISTTIMEFORMAT</B>
9269
17345e5a
JA
9270</FONT>
9271variable is set, time stamps are written to the history file, marked
9272with the history comment character, so
9273they may be preserved across shell sessions.
9274This uses the history comment character to distinguish timestamps from
9275other history lines.
9276After saving the history, the history file is truncated
9277to contain no more than
9278<FONT SIZE=-1><B>HISTFILESIZE</B>
9279
9280</FONT>
9281lines. If
9282<FONT SIZE=-1><B>HISTFILESIZE</B>
9283
9284</FONT>
ac50fbac
CR
9285is unset, or set to null, a non-numeric value,
9286or a numeric value less than zero, the history file is not truncated.
17345e5a
JA
9287<P>
9288
9289The builtin command
9290<B>fc</B>
9291
9292(see
9293<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
9294
9295</FONT>
9296below) may be used to list or edit and re-execute a portion of
9297the history list.
9298The
9299<B>history</B>
9300
9301builtin may be used to display or modify the history list and
9302manipulate the history file.
9303When using command-line editing, search commands
9304are available in each editing mode that provide access to the
9305history list.
9306<P>
9307
9308The shell allows control over which commands are saved on the history
9309list. The
9310<FONT SIZE=-1><B>HISTCONTROL</B>
9311
9312</FONT>
9313and
9314<FONT SIZE=-1><B>HISTIGNORE</B>
9315
9316</FONT>
9317variables may be set to cause the shell to save only a subset of the
9318commands entered.
9319The
9320<B>cmdhist</B>
9321
9322shell option, if enabled, causes the shell to attempt to save each
9323line of a multi-line command in the same history entry, adding
9324semicolons where necessary to preserve syntactic correctness.
9325The
9326<B>lithist</B>
9327
9328shell option causes the shell to save the command with embedded newlines
9329instead of semicolons. See the description of the
9330<B>shopt</B>
9331
9332builtin below under
9333<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
9334
9335</FONT>
9336for information on setting and unsetting shell options.
9337<A NAME="lbCX">&nbsp;</A>
9338<H3>HISTORY EXPANSION</H3>
9339
17345e5a
JA
9340The shell supports a history expansion feature that
9341is similar to the history expansion in
d233b485 9342<B>csh</B>.
17345e5a
JA
9343
9344This section describes what syntax features are available. This
9345feature is enabled by default for interactive shells, and can be
9346disabled using the
9347<B>+H</B>
9348
9349option to the
9350<B>set</B>
9351
9352builtin command (see
9353<FONT SIZE=-1><B>SHELL BUILTIN COMMANDS</B>
9354
9355</FONT>
9356below). Non-interactive shells do not perform history expansion
9357by default.
9358<P>
9359
9360History expansions introduce words from the history list into
9361the input stream, making it easy to repeat commands, insert the
9362arguments to a previous command into the current input line, or
9363fix errors in previous commands quickly.
9364<P>
9365
9366History expansion is performed immediately after a complete line
d233b485
CR
9367is read, before the shell breaks it into words, and is performed
9368on each line individually without taking quoting on previous lines into
9369account.
17345e5a
JA
9370It takes place in two parts.
9371The first is to determine which line from the history list
9372to use during substitution.
9373The second is to select portions of that line for inclusion into
9374the current one.
9375The line selected from the history is the <I>event</I>,
9376and the portions of that line that are acted upon are <I>words</I>.
9377Various <I>modifiers</I> are available to manipulate the selected words.
9378The line is broken into words in the same fashion as when reading input,
9379so that several <I>metacharacter</I>-separated words surrounded by
9380quotes are considered one word.
9381History expansions are introduced by the appearance of the
9382history expansion character, which is <B>!</B> by default.
9383Only backslash (<B>\</B>) and single quotes can quote
a0c0a00f
CR
9384the history expansion character, but the history expansion character is
9385also treated as quoted if it immediately precedes the closing double quote
9386in a double-quoted string.
17345e5a
JA
9387<P>
9388
9389Several characters inhibit history expansion if found immediately
9390following the history expansion character, even if it is unquoted:
9391space, tab, newline, carriage return, and <B>=</B>.
9392If the <B>extglob</B> shell option is enabled, <B>(</B> will also
9393inhibit expansion.
9394<P>
9395
9396Several shell options settable with the
9397<B>shopt</B>
9398
9399builtin may be used to tailor the behavior of history expansion.
9400If the
9401<B>histverify</B>
9402
9403shell option is enabled (see the description of the
9404<B>shopt</B>
9405
0001803f 9406builtin below), and
17345e5a
JA
9407<B>readline</B>
9408
9409is being used, history substitutions are not immediately passed to
9410the shell parser.
9411Instead, the expanded line is reloaded into the
9412<B>readline</B>
9413
9414editing buffer for further modification.
9415If
9416<B>readline</B>
9417
9418is being used, and the
9419<B>histreedit</B>
9420
9421shell option is enabled, a failed history substitution will be reloaded
9422into the
9423<B>readline</B>
9424
9425editing buffer for correction.
9426The
9427<B>-p</B>
9428
9429option to the
9430<B>history</B>
9431
9432builtin command may be used to see what a history expansion will
9433do before using it.
9434The
9435<B>-s</B>
9436
9437option to the
9438<B>history</B>
9439
9440builtin may be used to add commands to the end of the history list
9441without actually executing them, so that they are available for
9442subsequent recall.
9443<P>
9444
9445The shell allows control of the various characters used by the
9446history expansion mechanism (see the description of
9447<B>histchars</B>
9448
9449above under
9450<B>Shell Variables</B>).
9451
9452The shell uses
9453the history comment character to mark history timestamps when
9454writing the history file.
9455<A NAME="lbCY">&nbsp;</A>
9456<H4>Event Designators</H4>
9457
17345e5a
JA
9458An event designator is a reference to a command line entry in the
9459history list.
495aee44
CR
9460Unless the reference is absolute, events are relative to the current
9461position in the history list.
17345e5a
JA
9462<P>
9463
9464
9465<DL COMPACT>
9466<DT><B>!</B>
9467
9468<DD>
9469Start a history substitution, except when followed by a
9470<B>blank</B>,
9471
9472newline, carriage return, =
9473or ( (when the <B>extglob</B> shell option is enabled using
9474the <B>shopt</B> builtin).
9475<DT><B>!</B><I>n</I>
9476
9477<DD>
9478Refer to command line
9479<I>n</I>.
9480
9481<DT><B>!-</B><I>n</I>
9482
9483<DD>
495aee44 9484Refer to the current command minus
17345e5a
JA
9485<I>n</I>.
9486
9487<DT><B>!!</B>
9488
9489<DD>
9490Refer to the previous command. This is a synonym for `!-1'.
9491<DT><B>!</B><I>string</I>
9492
9493<DD>
495aee44
CR
9494Refer to the most recent command preceding the current position in the
9495history list starting with
17345e5a
JA
9496<I>string</I>.
9497
9498<DT><B>!?</B><I>string</I><B>[?]</B>
9499
9500<DD>
ac50fbac 9501Refer to the most recent command preceding the current position in the
495aee44 9502history list containing
17345e5a
JA
9503<I>string</I>.
9504
9505The trailing <B>?</B> may be omitted if
9506<I>string</I>
9507
9508is followed immediately by a newline.
8868edaf
CR
9509If <I>string</I> is missing, the string from the most recent search is used;
9510it is an error if there is no previous search string.
17345e5a
JA
9511<DT><B></B><FONT SIZE=+2><B>^</B></FONT><B></B><I>string1</I><FONT SIZE=+2>^</FONT><I>string2</I><FONT SIZE=+2>^</FONT>
9512
9513<DD>
495aee44 9514Quick substitution. Repeat the previous command, replacing
17345e5a
JA
9515<I>string1</I>
9516
9517with
9518<I>string2</I>.
9519
9520Equivalent to
8868edaf 9521``!!:s<FONT SIZE=+2>^</FONT><I>string1</I><FONT SIZE=+2>^</FONT><I>string2</I><FONT SIZE=+2>^</FONT>''
17345e5a
JA
9522(see <B>Modifiers</B> below).
9523<DT><B>!#</B>
9524
9525<DD>
9526The entire command line typed so far.
9527
9528</DL>
9529<A NAME="lbCZ">&nbsp;</A>
9530<H4>Word Designators</H4>
9531
17345e5a 9532Word designators are used to select desired words from the event.
a0c0a00f 9533A
17345e5a
JA
9534<B>:</B>
9535
9536separates the event specification from the word designator.
9537It may be omitted if the word designator begins with a
9538<B>^</B>,
9539
9540<B>$</B>,
9541
9542<B>*</B>,
9543
9544<B>-</B>,
9545
9546or
9547<B>%</B>.
9548
9549Words are numbered from the beginning of the line,
9550with the first word being denoted by 0 (zero).
9551Words are inserted into the current line separated by single spaces.
9552<P>
9553
9554
9555<DL COMPACT>
9556<DT><B>0 (zero)</B>
9557
9558<DD>
9559The zeroth word. For the shell, this is the command
9560word.
9561<DT><I>n</I>
9562
9563<DD>
9564The <I>n</I>th word.
9565<DT><B>^</B>
9566
9567<DD>
9568The first argument. That is, word 1.
9569<DT><B>$</B>
9570
9571<DD>
ac50fbac
CR
9572The last word. This is usually the last argument, but will expand to the
9573zeroth word if there is only one word in the line.
17345e5a
JA
9574<DT><B>%</B>
9575
9576<DD>
8868edaf
CR
9577The first word matched by the most recent `?<I>string</I>?' search,
9578if the search string begins with a character that is part of a word.
17345e5a
JA
9579<DT><I>x</I><B>-</B>y
9580
9581<DD>
9582A range of words; `-<I>y</I>' abbreviates `0-<I>y</I>'.
9583<DT><B>*</B>
9584
9585<DD>
9586All of the words but the zeroth. This is a synonym
9587for `<I>1-$</I>'. It is not an error to use
9588<B>*</B>
9589
9590if there is just one
9591word in the event; the empty string is returned in that case.
9592<DT><B>x*</B>
9593
9594<DD>
9595Abbreviates <I>x-$</I>.
9596<DT><B>x-</B>
9597
9598<DD>
9599Abbreviates <I>x-$</I> like <B>x*</B>, but omits the last word.
8868edaf 9600If <B>x</B> is missing, it defaults to 0.
17345e5a
JA
9601
9602</DL>
9603<P>
9604
9605If a word designator is supplied without an event specification, the
9606previous command is used as the event.
9607<A NAME="lbDA">&nbsp;</A>
9608<H4>Modifiers</H4>
9609
17345e5a
JA
9610After the optional word designator, there may appear a sequence of
9611one or more of the following modifiers, each preceded by a `:'.
8868edaf 9612These modify, or edit, the word or words selected from the history event.
17345e5a
JA
9613<P>
9614
9615
17345e5a
JA
9616<DL COMPACT>
9617<DT><B>h</B>
9618
9619<DD>
ac50fbac 9620Remove a trailing filename component, leaving only the head.
17345e5a
JA
9621<DT><B>t</B>
9622
9623<DD>
ac50fbac 9624Remove all leading filename components, leaving the tail.
17345e5a
JA
9625<DT><B>r</B>
9626
9627<DD>
9628Remove a trailing suffix of the form <I>.xxx</I>, leaving the
9629basename.
9630<DT><B>e</B>
9631
9632<DD>
9633Remove all but the trailing suffix.
9634<DT><B>p</B>
9635
9636<DD>
9637Print the new command but do not execute it.
9638<DT><B>q</B>
9639
9640<DD>
9641Quote the substituted words, escaping further substitutions.
9642<DT><B>x</B>
9643
9644<DD>
9645Quote the substituted words as with
9646<B>q</B>,
9647
9648but break into words at
9649<B>blanks</B>
9650
9651and newlines.
8868edaf
CR
9652The <B>q</B> and <B>x</B> modifiers are mutually exclusive; the last one
9653supplied is used.
17345e5a
JA
9654<DT><B>s/</B><I>old</I>/<I>new</I>/
9655
9656<DD>
9657Substitute
9658<I>new</I>
9659
9660for the first occurrence of
9661<I>old</I>
9662
8868edaf
CR
9663in the event line.
9664Any character may be used as the delimiter in place of /.
9665The final delimiter is optional if it is the last character of the
9666event line.
9667The delimiter may be quoted in
17345e5a
JA
9668<I>old</I>
9669
9670and
9671<I>new</I>
9672
9673with a single backslash. If &amp; appears in
9674<I>new</I>,
9675
9676it is replaced by
9677<I>old</I>.
9678
8868edaf
CR
9679A single backslash will quote the &amp;.
9680If
17345e5a
JA
9681<I>old</I>
9682
9683is null, it is set to the last
9684<I>old</I>
9685
9686substituted, or, if no previous history substitutions took place,
9687the last
9688<I>string</I>
9689
9690in a
9691<B>!?</B><I>string</I><B>[?]</B>
9692
9693search.
8868edaf
CR
9694If
9695<I>new</I>
9696
9697is null, each matching
9698<I>old</I>
9699
9700is deleted.
17345e5a
JA
9701<DT><B>&amp;</B>
9702
9703<DD>
9704Repeat the previous substitution.
9705<DT><B>g</B>
9706
9707<DD>
9708Cause changes to be applied over the entire event line. This is
9709used in conjunction with `<B>:s</B>' (e.g., `<B>:gs/</B><I>old</I>/<I>new</I>/')
9710or `<B>:&amp;</B>'. If used with
9711`<B>:s</B>', any delimiter can be used
9712in place of /, and the final delimiter is optional
9713if it is the last character of the event line.
9714An <B>a</B> may be used as a synonym for <B>g</B>.
9715<DT><B>G</B>
9716
9717<DD>
8868edaf
CR
9718Apply the following `<B>s</B>' or `<B>&amp;</B>' modifier once to each word
9719in the event line.
17345e5a
JA
9720
9721</DL>
9722<A NAME="lbDB">&nbsp;</A>
9723<H3>SHELL BUILTIN COMMANDS</H3>
9724
9725
9726
9727<P>
9728
9729Unless otherwise noted, each builtin command documented in this
9730section as accepting options preceded by
9731<B>-</B>
9732
9733accepts
9734<B>--</B>
9735
9736to signify the end of the options.
d233b485 9737The <B>:</B>, <B>true</B>, <B>false</B>, and <B>test</B>/<B>[</B> builtins
0001803f 9738do not accept options and do not treat <B>--</B> specially.
a0c0a00f
CR
9739The <B>exit</B>, <B>logout</B>, <B>return</B>,
9740<B>break</B>, <B>continue</B>, <B>let</B>,
0001803f
CR
9741and <B>shift</B> builtins accept and process arguments beginning with
9742<B>-</B> without requiring <B>--</B>.
9743Other builtins that accept arguments but are not specified as accepting
9744options interpret arguments beginning with <B>-</B> as invalid options and
9745require <B>--</B> to prevent this interpretation.
17345e5a
JA
9746<P>
9747
9748<DL COMPACT>
9749<DT><B>:</B> [<I>arguments</I>]<DD>
9750
9751No effect; the command does nothing beyond expanding
9752<I>arguments</I>
9753
9754and performing any specified
a0c0a00f
CR
9755redirections.
9756The return status is zero.
17345e5a
JA
9757<DT><B> . </B> <I>filename</I> [<I>arguments</I>]<DD>
9758
9759<DT><B>source</B> <I>filename</I> [<I>arguments</I>]<DD>
9760
9761Read and execute commands from
9762<I>filename</I>
9763
9764in the current
9765shell environment and return the exit status of the last command
9766executed from
9767<I>filename</I>.
9768
9769If
9770<I>filename</I>
9771
ac50fbac 9772does not contain a slash, filenames in
17345e5a
JA
9773<FONT SIZE=-1><B>PATH</B>
9774
9775</FONT>
9776are used to find the directory containing
74091dd4 9777<I>filename</I>,
17345e5a 9778
74091dd4 9779but <I>filename</I> does not need to be executable.
17345e5a
JA
9780The file searched for in
9781<FONT SIZE=-1><B>PATH</B>
9782
9783</FONT>
9784need not be executable.
74091dd4
CR
9785When <B>bash</B> is not in <I>posix mode</I>, it searches
9786the current directory if no file is found in
17345e5a
JA
9787<FONT SIZE=-1><B>PATH</B>.
9788
9789</FONT>
9790If the
9791<B>sourcepath</B>
9792
9793option to the
9794<B>shopt</B>
9795
9796builtin command is turned off, the
9797<FONT SIZE=-1><B>PATH</B>
9798
9799</FONT>
9800is not searched.
9801If any <I>arguments</I> are supplied, they become the positional
9802parameters when <I>filename</I> is executed. Otherwise the positional
9803parameters are unchanged.
74091dd4 9804If the <B>-T</B> option is enabled, <B>.</B> inherits any trap on
a0c0a00f 9805<B>DEBUG</B>; if it is not, any <B>DEBUG</B> trap string is saved and
74091dd4 9806restored around the call to <B>.</B>, and <B>.</B> unsets the
a0c0a00f
CR
9807<B>DEBUG</B> trap while it executes.
9808If <B>-T</B> is not set, and the sourced file changes
74091dd4 9809the <B>DEBUG</B> trap, the new value is retained when <B>.</B> completes.
17345e5a
JA
9810The return status is the status of the last command exited within
9811the script (0 if no commands are executed), and false if
9812<I>filename</I>
9813
9814is not found or cannot be read.
9815<DT><B>alias</B> [<B>-p</B>] [<I>name</I>[=<I>value</I>] ...]<DD>
9816<B>Alias</B> with no arguments or with the
9817<B>-p</B>
9818
9819option prints the list of aliases in the form
9820<B>alias</B> <I>name</I>=<I>value</I> on standard output.
9821When arguments are supplied, an alias is defined for
9822each <I>name</I> whose <I>value</I> is given.
a0c0a00f 9823A trailing space in <I>value</I> causes the next word to be
17345e5a
JA
9824checked for alias substitution when the alias is expanded.
9825For each <I>name</I> in the argument list for which no <I>value</I>
9826is supplied, the name and value of the alias is printed.
9827<B>Alias</B> returns true unless a <I>name</I> is given for which
9828no alias has been defined.
9829<DT><B>bg</B> [<I>jobspec</I> ...]<DD>
9830Resume each suspended job <I>jobspec</I> in the background, as if it
9831had been started with
9832<B>&amp;</B>.
9833
9834If
9835<I>jobspec</I>
9836
9837is not present, the shell's notion of the <I>current job</I> is used.
9838<B>bg</B>
9839
9840<I>jobspec</I>
9841
9842returns 0 unless run when job control is disabled or, when run with
9843job control enabled, any specified <I>jobspec</I> was not found
9844or was started without job control.
ac50fbac 9845<DT><B>bind</B> [<B>-m</B> <I>keymap</I>] [<B>-lpsvPSVX</B>]<DD>
17345e5a
JA
9846
9847<DT><B>bind</B> [<B>-m</B> <I>keymap</I>] [<B>-q</B> <I>function</I>] [<B>-u</B> <I>function</I>] [<B>-r</B> <I>keyseq</I>]<DD>
9848<DT><B>bind</B> [<B>-m</B> <I>keymap</I>] <B>-f</B> <I>filename</I><DD>
9849<DT><B>bind</B> [<B>-m</B> <I>keymap</I>] <B>-x</B> <I>keyseq</I>:<I>shell-command</I><DD>
9850<DT><B>bind</B> [<B>-m</B> <I>keymap</I>] <I>keyseq</I>:<I>function-name</I><DD>
a0c0a00f 9851<DT><B>bind</B> [<B>-m</B> <I>keymap</I>] <I>keyseq</I>:<I>readline-command</I><DD>
74091dd4 9852<DT><B>bind</B> <I>readline-command-line</I><DD>
17345e5a
JA
9853
9854Display current
9855<B>readline</B>
9856
9857key and function bindings, bind a key sequence to a
9858<B>readline</B>
9859
9860function or macro, or set a
9861<B>readline</B>
9862
9863variable.
74091dd4
CR
9864Each non-option argument is a command as it would appear in a
9865<B>readline</B>
9866
9867initialization file such as
17345e5a
JA
9868<I>.inputrc</I>,
9869
9870but each binding or command must be passed as a separate argument;
9871e.g., '&quot;\C-x\C-r&quot;: re-read-init-file'.
9872Options, if supplied, have the following meanings:
9873<DL COMPACT><DT><DD>
9874
9875<DL COMPACT>
9876<DT><B>-m </B><I>keymap</I>
9877
9878<DD>
9879Use
9880<I>keymap</I>
9881
9882as the keymap to be affected by the subsequent bindings.
9883Acceptable
9884<I>keymap</I>
9885
9886names are
9887<I>emacs, emacs-standard, emacs-meta, emacs-ctlx, vi,
9888vi-move, vi-command</I>, and
9889<I>vi-insert</I>.
9890
a0c0a00f
CR
9891<I>vi</I> is equivalent to <I>vi-command</I> (<I>vi-move</I> is also
9892a synonym); <I>emacs</I> is
17345e5a
JA
9893equivalent to <I>emacs-standard</I>.
9894<DT><B>-l</B>
9895
9896<DD>
9897List the names of all <B>readline</B> functions.
9898<DT><B>-p</B>
9899
9900<DD>
9901Display <B>readline</B> function names and bindings in such a way
9902that they can be re-read.
9903<DT><B>-P</B>
9904
9905<DD>
9906List current <B>readline</B> function names and bindings.
9907<DT><B>-s</B>
9908
9909<DD>
9910Display <B>readline</B> key sequences bound to macros and the strings
9911they output in such a way that they can be re-read.
9912<DT><B>-S</B>
9913
9914<DD>
9915Display <B>readline</B> key sequences bound to macros and the strings
9916they output.
9917<DT><B>-v</B>
9918
9919<DD>
9920Display <B>readline</B> variable names and values in such a way that they
9921can be re-read.
9922<DT><B>-V</B>
9923
9924<DD>
9925List current <B>readline</B> variable names and values.
9926<DT><B>-f </B><I>filename</I>
9927
9928<DD>
9929Read key bindings from <I>filename</I>.
9930<DT><B>-q </B><I>function</I>
9931
9932<DD>
9933Query about which keys invoke the named <I>function</I>.
9934<DT><B>-u </B><I>function</I>
9935
9936<DD>
9937Unbind all keys bound to the named <I>function</I>.
9938<DT><B>-r </B><I>keyseq</I>
9939
9940<DD>
9941Remove any current binding for <I>keyseq</I>.
9942<DT><B>-x </B><I>keyseq</I>:<I>shell-command</I>
9943
9944<DD>
9945Cause <I>shell-command</I> to be executed whenever <I>keyseq</I> is
9946entered.
9947When <I>shell-command</I> is executed, the shell sets the
0001803f 9948<FONT SIZE=-1><B>READLINE_LINE</B>
17345e5a 9949
0001803f 9950</FONT>
17345e5a 9951variable to the contents of the <B>readline</B> line buffer and the
0001803f 9952<FONT SIZE=-1><B>READLINE_POINT</B>
17345e5a 9953
0001803f 9954</FONT>
8868edaf
CR
9955and
9956<FONT SIZE=-1><B>READLINE_MARK</B>
9957
9958</FONT>
9959variables to the current location of the insertion point and the saved
9960insertion point (the mark), respectively.
74091dd4
CR
9961The shell assigns any numeric argument the user supplied to the
9962<FONT SIZE=-1><B>READLINE_ARGUMENT</B>
9963
9964</FONT>
9965variable.
9966If there was no argument, that variable is not set.
8868edaf
CR
9967If the executed command changes the value of any of
9968<FONT SIZE=-1><B>READLINE_LINE</B>,
17345e5a 9969
0001803f 9970</FONT>
0001803f 9971<FONT SIZE=-1><B>READLINE_POINT</B>,
17345e5a 9972
8868edaf
CR
9973</FONT>
9974or
9975<FONT SIZE=-1><B>READLINE_MARK</B>,
9976
0001803f 9977</FONT>
17345e5a 9978those new values will be reflected in the editing state.
ac50fbac
CR
9979<DT><B>-X</B>
9980
9981<DD>
9982List all key sequences bound to shell commands and the associated commands
9983in a format that can be reused as input.
17345e5a
JA
9984
9985</DL>
9986<P>
9987
9988The return value is 0 unless an unrecognized option is given or an
9989error occurred.
9990</DL>
9991
9992<DT><B>break</B> [<I>n</I>]<DD>
9993Exit from within a
9994<B>for</B>,
9995
9996<B>while</B>,
9997
9998<B>until</B>,
9999
10000or
10001<B>select</B>
10002
10003loop. If <I>n</I> is specified, break <I>n</I> levels.
10004<I>n</I>
10005
10006must be >= 1. If
10007<I>n</I>
10008
10009is greater than the number of enclosing loops, all enclosing loops
10010are exited.
10011The return value is 0 unless <I>n</I> is not greater than or equal to 1.
10012<DT><B>builtin</B> <I>shell-builtin</I> [<I>arguments</I>]<DD>
10013Execute the specified shell builtin, passing it
10014<I>arguments</I>,
10015
10016and return its exit status.
10017This is useful when defining a
10018function whose name is the same as a shell builtin,
10019retaining the functionality of the builtin within the function.
10020The <B>cd</B> builtin is commonly redefined this way.
10021The return status is false if
10022<I>shell-builtin</I>
10023
10024is not a shell builtin command.
10025<DT><B>caller</B> [<I>expr</I>]<DD>
10026Returns the context of any active subroutine call (a shell function or
495aee44 10027a script executed with the <B>.</B> or <B>source</B> builtins).
17345e5a
JA
10028Without <I>expr</I>, <B>caller</B> displays the line number and source
10029filename of the current subroutine call.
a0c0a00f 10030If a non-negative integer is supplied as <I>expr</I>, <B>caller</B>
17345e5a
JA
10031displays the line number, subroutine name, and source file corresponding
10032to that position in the current execution call stack. This extra
10033information may be used, for example, to print a stack trace. The
10034current frame is frame 0.
10035The return value is 0 unless the shell is not executing a subroutine
10036call or <I>expr</I> does not correspond to a valid position in the
10037call stack.
ac50fbac
CR
10038<DT><B>cd</B> [<B>-L</B>|[<B>-P</B> [<B>-e</B>]] [-@]] [<I>dir</I>]<DD>
10039Change the current directory to <I>dir</I>.
10040if <I>dir</I> is not supplied, the value of the
17345e5a
JA
10041<FONT SIZE=-1><B>HOME</B>
10042
10043</FONT>
ac50fbac 10044shell variable is the default.
17345e5a
JA
10045The variable
10046<FONT SIZE=-1><B>CDPATH</B>
10047
10048</FONT>
10049defines the search path for the directory containing
ac50fbac
CR
10050<I>dir</I>:
10051
10052each directory name in
10053<FONT SIZE=-1><B>CDPATH</B>
17345e5a 10054
ac50fbac
CR
10055</FONT>
10056is searched for <I>dir</I>.
17345e5a
JA
10057Alternative directory names in
10058<FONT SIZE=-1><B>CDPATH</B>
10059
10060</FONT>
10061are separated by a colon (:). A null directory name in
10062<FONT SIZE=-1><B>CDPATH</B>
10063
10064</FONT>
10065is the same as the current directory, i.e., ``<B>.</B>''. If
10066<I>dir</I>
10067
10068begins with a slash (/),
10069then
10070<FONT SIZE=-1><B>CDPATH</B>
10071
10072</FONT>
a0c0a00f 10073is not used. The
17345e5a
JA
10074<B>-P</B>
10075
ac50fbac
CR
10076option causes <B>cd</B> to use the physical directory structure
10077by resolving symbolic links while traversing <I>dir</I> and
10078before processing instances of <I>..</I> in <I>dir</I> (see also the
17345e5a
JA
10079<B>-P</B>
10080
10081option to the
10082<B>set</B>
10083
10084builtin command); the
10085<B>-L</B>
10086
ac50fbac
CR
10087option forces symbolic links to be followed by resolving the link
10088after processing instances of <I>..</I> in <I>dir</I>.
10089If <I>..</I> appears in <I>dir</I>, it is processed by removing the
10090immediately previous pathname component from <I>dir</I>, back to a slash
10091or the beginning of <I>dir</I>.
495aee44
CR
10092If the
10093<B>-e</B>
10094
10095option is supplied with
10096<B>-P</B>,
10097
10098and the current working directory cannot be successfully determined
10099after a successful directory change, <B>cd</B> will return an unsuccessful
10100status.
ac50fbac
CR
10101On systems that support it, the <B>-@</B> option presents the extended
10102attributes associated with a file as a directory.
495aee44 10103An argument of
17345e5a
JA
10104<B>-</B>
10105
ac50fbac
CR
10106is converted to
10107<FONT SIZE=-1><B>$OLDPWD</B>
17345e5a
JA
10108
10109</FONT>
ac50fbac 10110before the directory change is attempted.
0001803f
CR
10111If a non-empty directory name from
10112<FONT SIZE=-1><B>CDPATH</B>
10113
10114</FONT>
10115is used, or if
17345e5a
JA
10116<B>-</B> is the first argument, and the directory change is
10117successful, the absolute pathname of the new working directory is
10118written to the standard output.
74091dd4
CR
10119If the directory change is successful, <B>cd</B> sets the value of the
10120<B>PWD</B> environment variable to the new directory name, and sets the
10121<B>OLDPWD</B> environment variable to the value of the current working
10122directory before the change.
17345e5a
JA
10123The return value is true if the directory was successfully changed;
10124false otherwise.
10125<DT><B>command</B> [<B>-pVv</B>] <I>command</I> [<I>arg</I> ...]<DD>
10126Run
10127<I>command</I>
10128
10129with
10130<I>args</I>
10131
a0c0a00f
CR
10132suppressing the normal shell function lookup.
10133Only builtin commands or commands found in the
17345e5a
JA
10134<FONT SIZE=-1><B>PATH</B>
10135
10136</FONT>
10137are executed. If the
10138<B>-p</B>
10139
10140option is given, the search for
10141<I>command</I>
10142
10143is performed using a default value for
0001803f 10144<FONT SIZE=-1><B>PATH</B>
17345e5a 10145
0001803f 10146</FONT>
17345e5a
JA
10147that is guaranteed to find all of the standard utilities.
10148If either the
10149<B>-V</B>
10150
10151or
10152<B>-v</B>
10153
10154option is supplied, a description of
10155<I>command</I>
10156
10157is printed. The
10158<B>-v</B>
10159
ac50fbac 10160option causes a single word indicating the command or filename
17345e5a
JA
10161used to invoke
10162<I>command</I>
10163
10164to be displayed; the
10165<B>-V</B>
10166
10167option produces a more verbose description.
10168If the
10169<B>-V</B>
10170
10171or
10172<B>-v</B>
10173
10174option is supplied, the exit status is 0 if
10175<I>command</I>
10176
10177was found, and 1 if not. If neither option is supplied and
10178an error occurred or
10179<I>command</I>
10180
10181cannot be found, the exit status is 127. Otherwise, the exit status of the
10182<B>command</B>
10183
10184builtin is the exit status of
10185<I>command</I>.
10186
10187<DT><B>compgen</B> [<I>option</I>] [<I>word</I>]<DD>
10188Generate possible completion matches for <I>word</I> according to
10189the <I>option</I>s, which may be any option accepted by the
10190<B>complete</B>
10191
10192builtin with the exception of <B>-p</B> and <B>-r</B>, and write
10193the matches to the standard output.
10194When using the <B>-F</B> or <B>-C</B> options, the various shell variables
10195set by the programmable completion facilities, while available, will not
10196have useful values.
10197<P>
10198The matches will be generated in the same way as if the programmable
10199completion code had generated them directly from a completion specification
10200with the same flags.
10201If <I>word</I> is specified, only those completions matching <I>word</I>
10202will be displayed.
10203<P>
10204The return value is true unless an invalid option is supplied, or no
10205matches were generated.
8868edaf 10206<DT><B>complete</B> [<B>-abcdefgjksuv</B>] [<B>-o</B> <I>comp-option</I>] [<B>-DEI</B>] [<B>-A</B> <I>action</I>] [<B>-G</B> <I>globpat</I>] [<B>-W</B> <I>wordlist</I>]<DD>
17345e5a
JA
10207<BR>
10208
8868edaf 10209[<B>-F</B> <I>function</I>] [<B>-C</B> <I>command</I>] [<B>-X</B> <I>filterpat</I>] [<B>-P</B> <I>prefix</I>] [<B>-S</B> <I>suffix</I>] <I>name</I> [<I>name ...</I>]
17345e5a 10210
d233b485 10211<DT><B>complete</B> <B>-pr</B> [<B>-DEI</B>] [<I>name</I> ...]<DD>
17345e5a
JA
10212
10213Specify how arguments to each <I>name</I> should be completed.
10214If the <B>-p</B> option is supplied, or if no options are supplied,
10215existing completion specifications are printed in a way that allows
10216them to be reused as input.
10217The <B>-r</B> option removes a completion specification for
10218each <I>name</I>, or, if no <I>name</I>s are supplied, all
10219completion specifications.
d233b485 10220The <B>-D</B> option indicates that other supplied options and actions should
0001803f
CR
10221apply to the ``default'' command completion; that is, completion attempted
10222on a command for which no completion has previously been defined.
d233b485 10223The <B>-E</B> option indicates that other supplied options and actions should
17345e5a
JA
10224apply to ``empty'' command completion; that is, completion attempted on a
10225blank line.
d233b485 10226The <B>-I</B> option indicates that other supplied options and actions should
8868edaf 10227apply to completion on the initial non-assignment word on the line, or after
d233b485
CR
10228a command delimiter such as <B>;</B> or <B>|</B>, which is usually command
10229name completion.
10230If multiple options are supplied, the <B>-D</B> option takes precedence
10231over <B>-E</B>, and both take precedence over <B>-I</B>.
10232If any of <B>-D</B>, <B>-E</B>, or <B>-I</B> are supplied, any other
10233<I>name</I> arguments are ignored; these completions only apply to the case
10234specified by the option.
17345e5a
JA
10235<P>
10236The process of applying these completion specifications when word completion
74091dd4
CR
10237is attempted is described
10238
10239above under <B>Programmable Completion</B>.
17345e5a
JA
10240<P>
10241Other options, if specified, have the following meanings.
10242The arguments to the <B>-G</B>, <B>-W</B>, and <B>-X</B> options
10243(and, if necessary, the <B>-P</B> and <B>-S</B> options)
10244should be quoted to protect them from expansion before the
10245<B>complete</B>
10246
10247builtin is invoked.
10248<DL COMPACT><DT><DD>
10249
10250<DL COMPACT>
10251<DT><B>-o</B> <I>comp-option</I><DD>
10252The <I>comp-option</I> controls several aspects of the compspec's behavior
10253beyond the simple generation of completions.
10254<I>comp-option</I> may be one of:
10255<DL COMPACT><DT><DD>
10256<DL COMPACT>
10257<DT><B>bashdefault</B>
10258
10259<DD>
10260Perform the rest of the default <B>bash</B> completions if the compspec
10261generates no matches.
10262<DT><B>default</B>
10263
10264<DD>
10265Use readline's default filename completion if the compspec generates
10266no matches.
10267<DT><B>dirnames</B>
10268
10269<DD>
10270Perform directory name completion if the compspec generates no matches.
10271<DT><B>filenames</B>
10272
10273<DD>
10274Tell readline that the compspec generates filenames, so it can perform any
10275filename-specific processing (like adding a slash to directory names,
10276quoting special characters, or suppressing trailing spaces).
10277Intended to be used with shell functions.
ac50fbac
CR
10278<DT><B>noquote</B>
10279
10280<DD>
10281Tell readline not to quote the completed words if they are filenames
10282(quoting filenames is the default).
a0c0a00f
CR
10283<DT><B>nosort</B>
10284
10285<DD>
10286Tell readline not to sort the list of possible completions alphabetically.
17345e5a
JA
10287<DT><B>nospace</B>
10288
10289<DD>
10290Tell readline not to append a space (the default) to words completed at
10291the end of the line.
10292<DT><B>plusdirs</B>
10293
10294<DD>
a0c0a00f 10295After any matches defined by the compspec are generated,
17345e5a
JA
10296directory name completion is attempted and any
10297matches are added to the results of the other actions.
10298</DL></DL>
10299
10300<DT><B>-A</B> <I>action</I><DD>
10301The <I>action</I> may be one of the following to generate a list of possible
10302completions:
10303<DL COMPACT><DT><DD>
10304<DL COMPACT>
10305<DT><B>alias</B>
10306
10307<DD>
10308Alias names. May also be specified as <B>-a</B>.
10309<DT><B>arrayvar</B>
10310
10311<DD>
10312Array variable names.
10313<DT><B>binding</B>
10314
10315<DD>
10316<B>Readline</B> key binding names.
10317<DT><B>builtin</B>
10318
10319<DD>
10320Names of shell builtin commands. May also be specified as <B>-b</B>.
10321<DT><B>command</B>
10322
10323<DD>
10324Command names. May also be specified as <B>-c</B>.
10325<DT><B>directory</B>
10326
10327<DD>
10328Directory names. May also be specified as <B>-d</B>.
10329<DT><B>disabled</B>
10330
10331<DD>
10332Names of disabled shell builtins.
10333<DT><B>enabled</B>
10334
10335<DD>
10336Names of enabled shell builtins.
10337<DT><B>export</B>
10338
10339<DD>
10340Names of exported shell variables. May also be specified as <B>-e</B>.
10341<DT><B>file</B>
10342
10343<DD>
10344File names. May also be specified as <B>-f</B>.
10345<DT><B>function</B>
10346
10347<DD>
10348Names of shell functions.
10349<DT><B>group</B>
10350
10351<DD>
10352Group names. May also be specified as <B>-g</B>.
10353<DT><B>helptopic</B>
10354
10355<DD>
10356Help topics as accepted by the <B>help</B> builtin.
10357<DT><B>hostname</B>
10358
10359<DD>
10360Hostnames, as taken from the file specified by the
10361<FONT SIZE=-1><B>HOSTFILE</B>
10362
10363</FONT>
10364shell variable.
10365<DT><B>job</B>
10366
10367<DD>
10368Job names, if job control is active. May also be specified as <B>-j</B>.
10369<DT><B>keyword</B>
10370
10371<DD>
10372Shell reserved words. May also be specified as <B>-k</B>.
10373<DT><B>running</B>
10374
10375<DD>
10376Names of running jobs, if job control is active.
10377<DT><B>service</B>
10378
10379<DD>
10380Service names. May also be specified as <B>-s</B>.
10381<DT><B>setopt</B>
10382
10383<DD>
10384Valid arguments for the <B>-o</B> option to the <B>set</B> builtin.
10385<DT><B>shopt</B>
10386
10387<DD>
10388Shell option names as accepted by the <B>shopt</B> builtin.
10389<DT><B>signal</B>
10390
10391<DD>
10392Signal names.
10393<DT><B>stopped</B>
10394
10395<DD>
10396Names of stopped jobs, if job control is active.
10397<DT><B>user</B>
10398
10399<DD>
10400User names. May also be specified as <B>-u</B>.
10401<DT><B>variable</B>
10402
10403<DD>
10404Names of all shell variables. May also be specified as <B>-v</B>.
10405</DL></DL>
10406
17345e5a
JA
10407<DT><B>-C</B> <I>command</I><DD>
10408<I>command</I> is executed in a subshell environment, and its output is
10409used as the possible completions.
74091dd4 10410Arguments are passed as with the <B>-F</B> option.
17345e5a
JA
10411<DT><B>-F</B> <I>function</I><DD>
10412The shell function <I>function</I> is executed in the current shell
10413environment.
ac50fbac
CR
10414When the function is executed,
10415the first argument (<B>$1</B>) is the name of the command whose arguments are
10416being completed,
10417the second argument (<B>$2</B>) is the word being completed,
10418and the third argument (<B>$3</B>) is the word preceding the word being
10419completed on the current command line.
17345e5a
JA
10420When it finishes, the possible completions are retrieved from the value
10421of the
10422<FONT SIZE=-1><B>COMPREPLY</B>
10423
10424</FONT>
10425array variable.
495aee44
CR
10426<DT><B>-G</B> <I>globpat</I><DD>
10427The pathname expansion pattern <I>globpat</I> is expanded to generate
10428the possible completions.
10429<DT><B>-P</B> <I>prefix</I><DD>
10430<I>prefix</I> is added at the beginning of each possible completion
10431after all other options have been applied.
10432<DT><B>-S</B> <I>suffix</I><DD>
10433<I>suffix</I> is appended to each possible completion
10434after all other options have been applied.
10435<DT><B>-W</B> <I>wordlist</I><DD>
10436The <I>wordlist</I> is split using the characters in the
10437<FONT SIZE=-1><B>IFS</B>
10438
10439</FONT>
10440special variable as delimiters, and each resultant word is expanded.
d233b485
CR
10441Shell quoting is honored within <I>wordlist</I>,
10442in order to provide a
10443mechanism for the words to contain shell metacharacters or characters
10444in the value of
10445<FONT SIZE=-1><B>IFS</B>.
10446
10447</FONT>
495aee44
CR
10448The possible completions are the members of the resultant list which
10449match the word being completed.
17345e5a 10450<DT><B>-X</B> <I>filterpat</I><DD>
0001803f 10451<I>filterpat</I> is a pattern as used for pathname expansion.
17345e5a
JA
10452It is applied to the list of possible completions generated by the
10453preceding options and arguments, and each completion matching
10454<I>filterpat</I> is removed from the list.
10455A leading <B>!</B> in <I>filterpat</I> negates the pattern; in this
10456case, any completion not matching <I>filterpat</I> is removed.
17345e5a
JA
10457
10458</DL>
10459<P>
10460
10461The return value is true unless an invalid option is supplied, an option
10462other than <B>-p</B> or <B>-r</B> is supplied without a <I>name</I>
10463argument, an attempt is made to remove a completion specification for
10464a <I>name</I> for which no specification exists, or
10465an error occurs adding a completion specification.
10466</DL>
10467
d233b485 10468<DT><B>compopt</B> [<B>-o</B> <I>option</I>] [<B>-DEI</B>] [<B>+o</B> <I>option</I>] [<I>name</I>]<DD>
17345e5a
JA
10469Modify completion options for each <I>name</I> according to the
10470<I>option</I>s, or for the
495aee44 10471currently-executing completion if no <I>name</I>s are supplied.
17345e5a
JA
10472If no <I>option</I>s are given, display the completion options for each
10473<I>name</I> or the current completion.
10474The possible values of <I>option</I> are those valid for the <B>complete</B>
10475builtin described above.
d233b485 10476The <B>-D</B> option indicates that other supplied options should
0001803f
CR
10477apply to the ``default'' command completion; that is, completion attempted
10478on a command for which no completion has previously been defined.
d233b485 10479The <B>-E</B> option indicates that other supplied options should
0001803f
CR
10480apply to ``empty'' command completion; that is, completion attempted on a
10481blank line.
d233b485 10482The <B>-I</B> option indicates that other supplied options should
8868edaf 10483apply to completion on the initial non-assignment word on the line,
d233b485
CR
10484or after a command delimiter such as <B>;</B> or <B>|</B>, which is usually
10485command name completion.
17345e5a 10486<P>
17345e5a
JA
10487The return value is true unless an invalid option is supplied, an attempt
10488is made to modify the options for a <I>name</I> for which no completion
10489specification exists, or an output error occurs.
17345e5a
JA
10490<DT><B>continue</B> [<I>n</I>]<DD>
10491Resume the next iteration of the enclosing
10492<B>for</B>,
10493
10494<B>while</B>,
10495
10496<B>until</B>,
10497
10498or
10499<B>select</B>
10500
10501loop.
10502If
10503<I>n</I>
10504
10505is specified, resume at the <I>n</I>th enclosing loop.
10506<I>n</I>
10507
10508must be >= 1. If
10509<I>n</I>
10510
10511is greater than the number of enclosing loops, the last enclosing loop
10512(the ``top-level'' loop) is resumed.
10513The return value is 0 unless <I>n</I> is not greater than or equal to 1.
8868edaf 10514<DT><B>declare</B> [<B>-aAfFgiIlnrtux</B>] [<B>-p</B>] [<I>name</I>[=<I>value</I>] ...]<DD>
17345e5a 10515
8868edaf 10516<DT><B>typeset</B> [<B>-aAfFgiIlnrtux</B>] [<B>-p</B>] [<I>name</I>[=<I>value</I>] ...]<DD>
17345e5a
JA
10517
10518Declare variables and/or give them attributes.
10519If no <I>name</I>s are given then display the values of variables.
10520The
10521<B>-p</B>
10522
10523option will display the attributes and values of each
10524<I>name</I>.
10525
10526When
10527<B>-p</B>
10528
ac50fbac
CR
10529is used with <I>name</I> arguments, additional options,
10530other than <B>-f</B> and <B>-F</B>, are ignored.
17345e5a
JA
10531When
10532<B>-p</B>
10533
10534is supplied without <I>name</I> arguments, it will display the attributes
10535and values of all variables having the attributes specified by the
10536additional options.
10537If no other options are supplied with <B>-p</B>, <B>declare</B> will display
10538the attributes and values of all shell variables. The <B>-f</B> option
10539will restrict the display to shell functions.
10540The
10541<B>-F</B>
10542
10543option inhibits the display of function definitions; only the
10544function name and attributes are printed.
10545If the <B>extdebug</B> shell option is enabled using <B>shopt</B>,
a0c0a00f
CR
10546the source file name and line number where each <I>name</I>
10547is defined are displayed as well. The
17345e5a
JA
10548<B>-F</B>
10549
10550option implies
10551<B>-f</B>.
10552
495aee44
CR
10553The
10554<B>-g</B>
10555
10556option forces variables to be created or modified at the global scope,
10557even when <B>declare</B> is executed in a shell function.
10558It is ignored in all other cases.
8868edaf
CR
10559The
10560<B>-I</B>
10561
10562option causes local variables to inherit the attributes
10563(except the <I>nameref</I> attribute)
10564and value of any existing variable with the same
10565<I>name</I> at a surrounding scope.
10566If there is no existing variable, the local variable is initially unset.
17345e5a
JA
10567The following options can
10568be used to restrict output to variables with the specified attribute or
10569to give variables attributes:
10570<DL COMPACT><DT><DD>
10571
10572<DL COMPACT>
10573<DT><B>-a</B>
10574
10575<DD>
10576Each <I>name</I> is an indexed array variable (see
10577<B>Arrays</B>
10578
74091dd4 10579
17345e5a
JA
10580above).
10581<DT><B>-A</B>
10582
10583<DD>
10584Each <I>name</I> is an associative array variable (see
10585<B>Arrays</B>
10586
74091dd4 10587
17345e5a
JA
10588above).
10589<DT><B>-f</B>
10590
10591<DD>
10592Use function names only.
10593<DT><B>-i</B>
10594
10595<DD>
10596The variable is treated as an integer; arithmetic evaluation (see
0001803f 10597<FONT SIZE=-1><B>ARITHMETIC EVALUATION</B>
17345e5a
JA
10598
10599</FONT>
74091dd4
CR
10600
10601above)
10602is performed when the variable is assigned a value.
17345e5a
JA
10603<DT><B>-l</B>
10604
10605<DD>
10606When the variable is assigned a value, all upper-case characters are
10607converted to lower-case.
10608The upper-case attribute is disabled.
ac50fbac
CR
10609<DT><B>-n</B>
10610
10611<DD>
10612Give each <I>name</I> the <I>nameref</I> attribute, making
10613it a name reference to another variable.
10614That other variable is defined by the value of <I>name</I>.
a0c0a00f
CR
10615All references, assignments, and attribute modifications
10616to <I>name</I>, except those using or changing the
ac50fbac
CR
10617<B>-n</B> attribute itself, are performed on the variable referenced by
10618<I>name</I>'s value.
a0c0a00f 10619The nameref attribute cannot be applied to array variables.
17345e5a
JA
10620<DT><B>-r</B>
10621
10622<DD>
10623Make <I>name</I>s readonly. These names cannot then be assigned values
10624by subsequent assignment statements or unset.
10625<DT><B>-t</B>
10626
10627<DD>
10628Give each <I>name</I> the <I>trace</I> attribute.
10629Traced functions inherit the <B>DEBUG</B> and <B>RETURN</B> traps from
10630the calling shell.
10631The trace attribute has no special meaning for variables.
10632<DT><B>-u</B>
10633
10634<DD>
10635When the variable is assigned a value, all lower-case characters are
10636converted to upper-case.
10637The lower-case attribute is disabled.
10638<DT><B>-x</B>
10639
10640<DD>
10641Mark <I>name</I>s for export to subsequent commands via the environment.
10642
10643</DL>
10644<P>
10645
10646Using `+' instead of `-'
10647turns off the attribute instead,
d233b485
CR
10648with the exceptions that <B>+a</B> and <B>+A</B>
10649may not be used to destroy array variables and <B>+r</B> will not
17345e5a 10650remove the readonly attribute.
ac50fbac
CR
10651When used in a function,
10652<B>declare</B>
10653
10654and
10655<B>typeset</B>
10656
10657make each
10658<I>name</I> local, as with the
17345e5a
JA
10659<B>local</B>
10660
495aee44 10661command,
ac50fbac
CR
10662unless the <B>-g</B> option is supplied.
10663If a variable name is followed by =<I>value</I>, the value of
17345e5a 10664the variable is set to <I>value</I>.
ac50fbac
CR
10665When using <B>-a</B> or <B>-A</B> and the compound assignment syntax to
10666create array variables, additional attributes do not take effect until
10667subsequent assignments.
17345e5a
JA
10668The return value is 0 unless an invalid option is encountered,
10669an attempt is made to define a function using
10670
10671<TT>-f foo=bar</TT>,
10672an attempt is made to assign a value to a readonly variable,
10673an attempt is made to assign a value to an array variable without
10674using the compound assignment syntax (see
10675<B>Arrays</B>
10676
74091dd4
CR
10677
10678above),
10679one of the <I>names</I> is not a valid shell variable name,
17345e5a
JA
10680an attempt is made to turn off readonly status for a readonly variable,
10681an attempt is made to turn off array status for an array variable,
10682or an attempt is made to display a non-existent function with <B>-f</B>.
10683</DL>
10684
ac50fbac 10685<DT><B>dirs [-clpv</B>] [+<I>n</I>] [-<I>n</I>]
17345e5a
JA
10686
10687<DD>
10688Without options, displays the list of currently remembered directories.
10689The default display is on a single line with directory names separated
10690by spaces.
a0c0a00f 10691Directories are added to the list with the
17345e5a
JA
10692<B>pushd</B>
10693
10694command; the
10695<B>popd</B>
10696
10697command removes entries from the list.
a0c0a00f 10698The current directory is always the first directory in the stack.
17345e5a
JA
10699<DL COMPACT><DT><DD>
10700
10701<DL COMPACT>
17345e5a
JA
10702<DT><B>-c</B>
10703
10704<DD>
10705Clears the directory stack by deleting all of the entries.
10706<DT><B>-l</B>
10707
10708<DD>
ac50fbac
CR
10709Produces a listing using full pathnames;
10710the default listing format uses a tilde to denote the home directory.
17345e5a
JA
10711<DT><B>-p</B>
10712
10713<DD>
10714Print the directory stack with one entry per line.
10715<DT><B>-v</B>
10716
10717<DD>
10718Print the directory stack with one entry per line,
10719prefixing each entry with its index in the stack.
ac50fbac
CR
10720<DT><B>+</B><I>n</I><DD>
10721Displays the <I>n</I>th entry counting from the left of the list
10722shown by
10723<B>dirs</B>
10724
10725when invoked without options, starting with zero.
10726<DT><B>-</B><I>n</I><DD>
10727Displays the <I>n</I>th entry counting from the right of the list
10728shown by
10729<B>dirs</B>
10730
10731when invoked without options, starting with zero.
17345e5a
JA
10732
10733</DL>
10734<P>
10735
10736The return value is 0 unless an
10737invalid option is supplied or <I>n</I> indexes beyond the end
10738of the directory stack.
10739</DL>
10740
a0c0a00f 10741<DT><B>disown</B> [<B>-ar</B>] [<B>-h</B>] [<I>jobspec</I> ... | <I>pid</I> ... ]<DD>
ac50fbac 10742Without options, remove each
17345e5a
JA
10743<I>jobspec</I>
10744
ac50fbac 10745from the table of active jobs.
17345e5a
JA
10746If
10747<I>jobspec</I>
10748
ac50fbac
CR
10749is not present, and neither the <B>-a</B> nor the <B>-r</B> option
10750is supplied, the <I>current job</I> is used.
17345e5a
JA
10751If the <B>-h</B> option is given, each
10752<I>jobspec</I>
10753
10754is not removed from the table, but is marked so that
10755<FONT SIZE=-1><B>SIGHUP</B>
10756
10757</FONT>
10758is not sent to the job if the shell receives a
10759<FONT SIZE=-1><B>SIGHUP</B>.
10760
10761</FONT>
10762If no
10763<I>jobspec</I>
10764
17345e5a
JA
10765is supplied, the
10766<B>-a</B>
10767
10768option means to remove or mark all jobs; the
10769<B>-r</B>
10770
10771option without a
10772<I>jobspec</I>
10773
10774argument restricts operation to running jobs.
10775The return value is 0 unless a
10776<I>jobspec</I>
10777
10778does not specify a valid job.
10779<DT><B>echo</B> [<B>-neE</B>] [<I>arg</I> ...]<DD>
10780Output the <I>arg</I>s, separated by spaces, followed by a newline.
ac50fbac 10781The return status is 0 unless a write error occurs.
17345e5a
JA
10782If <B>-n</B> is specified, the trailing newline is
10783suppressed. If the <B>-e</B> option is given, interpretation of
10784the following backslash-escaped characters is enabled. The
10785<B>-E</B>
10786
10787option disables the interpretation of these escape characters,
10788even on systems where they are interpreted by default.
10789The <B>xpg_echo</B> shell option may be used to
10790dynamically determine whether or not <B>echo</B> expands these
10791escape characters by default.
10792<B>echo</B>
10793
10794does not interpret <B>--</B> to mean the end of options.
10795<B>echo</B>
10796
10797interprets the following escape sequences:
10798<DL COMPACT><DT><DD>
10799
10800<DL COMPACT>
10801<DT><B>\a</B>
10802
10803<DD>
10804alert (bell)
10805<DT><B>\b</B>
10806
10807<DD>
10808backspace
10809<DT><B>\c</B>
10810
10811<DD>
10812suppress further output
10813<DT><B>\e</B>
10814
495aee44
CR
10815<DD>
10816<DT><B>\E</B>
10817
17345e5a
JA
10818<DD>
10819an escape character
10820<DT><B>\f</B>
10821
10822<DD>
10823form feed
10824<DT><B>\n</B>
10825
10826<DD>
10827new line
10828<DT><B>\r</B>
10829
10830<DD>
10831carriage return
10832<DT><B>\t</B>
10833
10834<DD>
10835horizontal tab
10836<DT><B>\v</B>
10837
10838<DD>
10839vertical tab
10840<DT><B>\\</B>
10841
10842<DD>
10843backslash
10844<DT><B>\0</B><I>nnn</I>
10845
10846<DD>
10847the eight-bit character whose value is the octal value <I>nnn</I>
10848(zero to three octal digits)
10849<DT><B>\x</B><I>HH</I>
10850
10851<DD>
10852the eight-bit character whose value is the hexadecimal value <I>HH</I>
10853(one or two hex digits)
495aee44
CR
10854<DT><B>\u</B><I>HHHH</I>
10855
10856<DD>
10857the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
10858<I>HHHH</I> (one to four hex digits)
10859<DT><B>\U</B><I>HHHHHHHH</I>
10860
10861<DD>
10862the Unicode (ISO/IEC 10646) character whose value is the hexadecimal value
10863<I>HHHHHHHH</I> (one to eight hex digits)
17345e5a
JA
10864
10865</DL></DL>
10866
10867<DT><B>enable</B> [<B>-a</B>] [<B>-dnps</B>] [<B>-f</B> <I>filename</I>] [<I>name</I> ...]<DD>
10868Enable and disable builtin shell commands.
10869Disabling a builtin allows a disk command which has the same name
10870as a shell builtin to be executed without specifying a full pathname,
10871even though the shell normally searches for builtins before disk commands.
10872If <B>-n</B> is used, each <I>name</I>
10873is disabled; otherwise,
10874<I>names</I> are enabled. For example, to use the
10875<B>test</B>
10876
10877binary found via the
10878<FONT SIZE=-1><B>PATH</B>
10879
10880</FONT>
10881instead of the shell builtin version, run
10882<TT>enable -n test</TT>.
10883
10884The
10885<B>-f</B>
10886
10887option means to load the new builtin command
10888<I>name</I>
10889
10890from shared object
10891<I>filename</I>,
10892
74091dd4
CR
10893on systems that support dynamic loading.
10894Bash will use the value of the <B>BASH_LOADABLES_PATH</B> variable as a
10895colon-separated list of directories in which to search for <I>filename</I>.
10896The default is system-dependent.
10897The
17345e5a
JA
10898<B>-d</B>
10899
10900option will delete a builtin previously loaded with
10901<B>-f</B>.
10902
10903If no <I>name</I> arguments are given, or if the
10904<B>-p</B>
10905
10906option is supplied, a list of shell builtins is printed.
10907With no other option arguments, the list consists of all enabled
10908shell builtins.
10909If <B>-n</B> is supplied, only disabled builtins are printed.
10910If <B>-a</B> is supplied, the list printed includes all builtins, with an
10911indication of whether or not each is enabled.
10912If <B>-s</B> is supplied, the output is restricted to the POSIX
10913<I>special</I> builtins.
74091dd4
CR
10914If no options are supplied and a <I>name</I> is not a shell builtin,
10915<B>enable</B> will attempt to load <I>name</I> from a shared object named
10916<I>name</I>, as if the command were
10917<TT>enable -f</TT> <I>name name</I> .
10918
17345e5a
JA
10919The return value is 0 unless a
10920<I>name</I>
10921
10922is not a shell builtin or there is an error loading a new builtin
10923from a shared object.
10924<DT><B>eval</B> [<I>arg</I> ...]<DD>
10925The <I>arg</I>s are read and concatenated together into a single
10926command. This command is then read and executed by the shell, and
10927its exit status is returned as the value of
10928<B>eval</B>.
10929
10930If there are no
10931<I>args</I>,
10932
10933or only null arguments,
10934<B>eval</B>
10935
10936returns 0.
10937<DT><B>exec</B> [<B>-cl</B>] [<B>-a</B> <I>name</I>] [<I>command</I> [<I>arguments</I>]]<DD>
10938If
10939<I>command</I>
10940
10941is specified, it replaces the shell.
10942No new process is created. The
10943<I>arguments</I>
10944
10945become the arguments to <I>command</I>.
10946If the
10947<B>-l</B>
10948
10949option is supplied,
a0c0a00f 10950the shell places a dash at the beginning of the zeroth argument passed to
17345e5a
JA
10951<I>command</I>.
10952
10953This is what
10954<I>login</I>(1)
10955
10956does. The
10957<B>-c</B>
10958
10959option causes
10960<I>command</I>
10961
10962to be executed with an empty environment. If
10963<B>-a</B>
10964
10965is supplied, the shell passes
10966<I>name</I>
10967
ac50fbac
CR
10968as the zeroth argument to the executed command.
10969If
17345e5a
JA
10970<I>command</I>
10971
10972cannot be executed for some reason, a non-interactive shell exits,
ac50fbac 10973unless the
17345e5a
JA
10974<B>execfail</B>
10975
ac50fbac
CR
10976shell option
10977is enabled. In that case, it returns failure.
17345e5a 10978An interactive shell returns failure if the file cannot be executed.
d233b485 10979A subshell exits unconditionally if <B>exec</B> fails.
17345e5a
JA
10980If
10981<I>command</I>
10982
10983is not specified, any redirections take effect in the current shell,
10984and the return status is 0. If there is a redirection error, the
10985return status is 1.
10986<DT><B>exit</B> [<I>n</I>]<DD>
10987Cause the shell to exit
10988with a status of <I>n</I>. If
10989<I>n</I>
10990
10991is omitted, the exit status
10992is that of the last command executed.
10993A trap on
10994<FONT SIZE=-1><B>EXIT</B>
10995
10996</FONT>
10997is executed before the shell terminates.
10998<DT><B>export</B> [<B>-fn</B>] [<I>name</I>[=<I>word</I>]] ...<DD>
10999
11000<DT><B>export -p</B>
11001
11002<DD>
11003
11004The supplied
11005<I>names</I>
11006
11007are marked for automatic export to the environment of
a0c0a00f 11008subsequently executed commands. If the
17345e5a
JA
11009<B>-f</B>
11010
a0c0a00f 11011option is given, the
17345e5a
JA
11012<I>names</I>
11013
11014refer to functions.
11015If no
11016<I>names</I>
11017
11018are given, or if the
11019<B>-p</B>
11020
11021option is supplied, a list
ac50fbac 11022of names of all exported variables is printed.
17345e5a
JA
11023The
11024<B>-n</B>
11025
11026option causes the export property to be removed from each
11027<I>name</I>.
11028If a variable name is followed by =<I>word</I>, the value of
11029the variable is set to <I>word</I>.
11030<B>export</B>
11031
11032returns an exit status of 0 unless an invalid option is
11033encountered,
11034one of the <I>names</I> is not a valid shell variable name, or
11035<B>-f</B>
11036
11037is supplied with a
11038<I>name</I>
11039
11040that is not a function.
11041<DT><B>fc</B> [<B>-e</B> <I>ename</I>] [<B>-lnr</B>] [<I>first</I>] [<I>last</I>]<DD>
11042
11043<DT><B>fc</B> <B>-s</B> [<I>pat</I>=<I>rep</I>] [<I>cmd</I>]<DD>
11044
ac50fbac 11045The first form selects a range of commands from
17345e5a
JA
11046<I>first</I>
11047
11048to
11049<I>last</I>
11050
ac50fbac 11051from the history list and displays or edits and re-executes them.
17345e5a
JA
11052<I>First</I>
11053
11054and
11055<I>last</I>
11056
11057may be specified as a string (to locate the last command beginning
11058with that string) or as a number (an index into the history list,
11059where a negative number is used as an offset from the current
8868edaf
CR
11060command number).
11061When listing, a <I>first</I> or <I>last</I> of
110620 is equivalent to -1 and -0 is equivalent to the current
11063command (usually the <B>fc</B> command); otherwise 0 is equivalent to -1
11064and -0 is invalid.
11065If
17345e5a
JA
11066<I>last</I>
11067
d233b485 11068is not specified, it is set to
17345e5a
JA
11069the current command for listing (so that
11070
11071<TT>fc -l -10</TT>
11072prints the last 10 commands) and to
11073<I>first</I>
11074
11075otherwise.
11076If
11077<I>first</I>
11078
d233b485 11079is not specified, it is set to the previous
17345e5a
JA
11080command for editing and -16 for listing.
11081<P>
11082The
11083<B>-n</B>
11084
11085option suppresses
11086the command numbers when listing. The
11087<B>-r</B>
11088
11089option reverses the order of
11090the commands. If the
11091<B>-l</B>
11092
11093option is given,
11094the commands are listed on
11095standard output. Otherwise, the editor given by
11096<I>ename</I>
11097
11098is invoked
11099on a file containing those commands. If
11100<I>ename</I>
11101
11102is not given, the
11103value of the
11104<FONT SIZE=-1><B>FCEDIT</B>
11105
11106</FONT>
11107variable is used, and
11108the value of
11109<FONT SIZE=-1><B>EDITOR</B>
11110
11111</FONT>
11112if
11113<FONT SIZE=-1><B>FCEDIT</B>
11114
11115</FONT>
11116is not set. If neither variable is set,
11117
11118<I>vi</I>
11119
11120is used. When editing is complete, the edited commands are
11121echoed and executed.
11122<P>
11123In the second form, <I>command</I> is re-executed after each instance
11124of <I>pat</I> is replaced by <I>rep</I>.
d233b485 11125<I>Command</I> is interpreted the same as <I>first</I> above.
17345e5a
JA
11126A useful alias to use with this is
11127
11128<TT>r='fc -s'</TT>,
11129so that typing
11130
11131<TT>r cc</TT>
11132runs the last command beginning with
11133
11134<TT>cc</TT>
11135and typing
11136
11137<TT>r</TT>
11138re-executes the last command.
11139<P>
11140If the first form is used, the return value is 0 unless an invalid
11141option is encountered or
11142<I>first</I>
11143
11144or
11145<I>last</I>
11146
11147specify history lines out of range.
11148If the
11149<B>-e</B>
11150
11151option is supplied, the return value is the value of the last
11152command executed or failure if an error occurs with the temporary
11153file of commands. If the second form is used, the return status
11154is that of the command re-executed, unless
11155<I>cmd</I>
11156
11157does not specify a valid history line, in which case
11158<B>fc</B>
11159
11160returns failure.
11161<DT><B>fg</B> [<I>jobspec</I>]<DD>
11162Resume
11163<I>jobspec</I>
11164
11165in the foreground, and make it the current job.
11166If
11167<I>jobspec</I>
11168
11169is not present, the shell's notion of the <I>current job</I> is used.
11170The return value is that of the command placed into the foreground,
11171or failure if run when job control is disabled or, when run with
11172job control enabled, if
11173<I>jobspec</I>
11174
11175does not specify a valid job or
11176<I>jobspec</I>
11177
11178specifies a job that was started without job control.
8868edaf 11179<DT><B>getopts</B> <I>optstring</I> <I>name</I> [<I>arg ...</I>]<DD>
17345e5a
JA
11180<B>getopts</B>
11181
11182is used by shell procedures to parse positional parameters.
11183<I>optstring</I>
11184
11185contains the option characters to be recognized; if a character
11186is followed by a colon, the option is expected to have an
11187argument, which should be separated from it by white space.
11188The colon and question mark characters may not be used as
11189option characters.
11190Each time it is invoked,
11191<B>getopts</B>
11192
11193places the next option in the shell variable
11194<I>name</I>,
11195
11196initializing
11197<I>name</I>
11198
11199if it does not exist,
11200and the index of the next argument to be processed into the
11201variable
11202<FONT SIZE=-1><B>OPTIND</B>.
11203
11204</FONT>
11205<FONT SIZE=-1><B>OPTIND</B>
11206
11207</FONT>
11208is initialized to 1 each time the shell or a shell script
11209is invoked. When an option requires an argument,
11210<B>getopts</B>
11211
11212places that argument into the variable
11213<FONT SIZE=-1><B>OPTARG</B>.
11214
11215</FONT>
11216The shell does not reset
11217<FONT SIZE=-1><B>OPTIND</B>
11218
11219</FONT>
11220automatically; it must be manually reset between multiple
11221calls to
11222<B>getopts</B>
11223
11224within the same shell invocation if a new set of parameters
11225is to be used.
11226<P>
11227When the end of options is encountered, <B>getopts</B> exits with a
11228return value greater than zero.
0001803f
CR
11229<FONT SIZE=-1><B>OPTIND</B>
11230
11231</FONT>
11232is set to the index of the first non-option argument,
495aee44 11233and <I>name</I> is set to ?.
17345e5a
JA
11234<P>
11235<B>getopts</B>
11236
11237normally parses the positional parameters, but if more arguments are
8868edaf
CR
11238supplied as
11239<I>arg</I>
17345e5a 11240
8868edaf 11241values,
17345e5a
JA
11242<B>getopts</B>
11243
11244parses those instead.
11245<P>
11246<B>getopts</B>
11247
11248can report errors in two ways. If the first character of
11249<I>optstring</I>
11250
11251is a colon,
11252<I>silent</I>
11253
ac50fbac 11254error reporting is used. In normal operation, diagnostic messages
17345e5a
JA
11255are printed when invalid options or missing option arguments are
11256encountered.
11257If the variable
11258<FONT SIZE=-1><B>OPTERR</B>
11259
11260</FONT>
11261is set to 0, no error messages will be displayed, even if the first
a0c0a00f 11262character of
17345e5a
JA
11263<I>optstring</I>
11264
11265is not a colon.
11266<P>
11267If an invalid option is seen,
11268<B>getopts</B>
11269
11270places ? into
11271<I>name</I>
11272
11273and, if not silent,
11274prints an error message and unsets
11275<FONT SIZE=-1><B>OPTARG</B>.
11276
11277</FONT>
11278If
11279<B>getopts</B>
11280
11281is silent,
11282the option character found is placed in
11283<FONT SIZE=-1><B>OPTARG</B>
11284
11285</FONT>
11286and no diagnostic message is printed.
11287<P>
11288If a required argument is not found, and
11289<B>getopts</B>
11290
11291is not silent,
11292a question mark (<B>?</B>) is placed in
11293<I>name</I>,
11294
11295<FONT SIZE=-1><B>OPTARG</B>
11296
11297</FONT>
11298is unset, and a diagnostic message is printed.
11299If
11300<B>getopts</B>
11301
11302is silent, then a colon (<B>:</B>) is placed in
11303<I>name</I>
11304
11305and
11306<FONT SIZE=-1><B>OPTARG</B>
11307
11308</FONT>
11309is set to the option character found.
11310<P>
11311<B>getopts</B>
11312
11313returns true if an option, specified or unspecified, is found.
11314It returns false if the end of options is encountered or an
11315error occurs.
11316<DT><B>hash</B> [<B>-lr</B>] [<B>-p</B> <I>filename</I>] [<B>-dt</B>] [<I>name</I>]<DD>
495aee44 11317Each time <B>hash</B> is invoked,
a0c0a00f 11318the full pathname of the command
495aee44 11319<I>name</I>
17345e5a 11320
495aee44 11321is determined by searching
17345e5a
JA
11322the directories in
11323<B>$PATH</B>
11324
495aee44 11325and remembered. Any previously-remembered pathname is discarded.
17345e5a
JA
11326If the
11327<B>-p</B>
11328
11329option is supplied, no path search is performed, and
11330<I>filename</I>
11331
ac50fbac 11332is used as the full filename of the command.
17345e5a
JA
11333The
11334<B>-r</B>
11335
11336option causes the shell to forget all
11337remembered locations.
11338The
11339<B>-d</B>
11340
11341option causes the shell to forget the remembered location of each <I>name</I>.
11342If the
11343<B>-t</B>
11344
11345option is supplied, the full pathname to which each <I>name</I> corresponds
11346is printed. If multiple <I>name</I> arguments are supplied with <B>-t</B>,
11347the <I>name</I> is printed before the hashed full pathname.
11348The
11349<B>-l</B>
11350
11351option causes output to be displayed in a format that may be reused as input.
11352If no arguments are given, or if only <B>-l</B> is supplied,
11353information about remembered commands is printed.
11354The return status is true unless a
11355<I>name</I>
11356
11357is not found or an invalid option is supplied.
11358<DT><B>help</B> [<B>-dms</B>] [<I>pattern</I>]<DD>
11359Display helpful information about builtin commands. If
11360<I>pattern</I>
11361
11362is specified,
11363<B>help</B>
11364
11365gives detailed help on all commands matching
11366<I>pattern</I>;
11367
11368otherwise help for all the builtins and shell control structures
11369is printed.
11370<DL COMPACT><DT><DD>
11371
11372<DL COMPACT>
11373<DT><B>-d</B>
11374
11375<DD>
11376Display a short description of each <I>pattern</I>
0001803f 11377<DT><B>-m</B>
17345e5a
JA
11378
11379<DD>
11380Display the description of each <I>pattern</I> in a manpage-like format
11381<DT><B>-s</B>
11382
11383<DD>
11384Display only a short usage synopsis for each <I>pattern</I>
11385
ac50fbac
CR
11386</DL>
11387<P>
17345e5a
JA
11388
11389The return status is 0 unless no command matches
11390<I>pattern</I>.
11391
ac50fbac
CR
11392</DL>
11393
17345e5a
JA
11394<DT><B>history [</B><I>n</I>]<DD>
11395
11396<DT><B>history</B> <B>-c</B><DD>
11397<DT><B>history -d</B> <I>offset</I><DD>
d233b485 11398<DT><B>history -d</B> <I>start</I>-<I>end</I><DD>
17345e5a
JA
11399<DT><B>history</B> <B>-anrw</B> [<I>filename</I>]<DD>
11400<DT><B>history</B> <B>-p</B> <I>arg</I> [<I>arg ...</I>]<DD>
11401<DT><B>history</B> <B>-s</B> <I>arg</I> [<I>arg ...</I>]<DD>
11402
11403With no options, display the command
11404history list with line numbers. Lines listed
a0c0a00f 11405with a
17345e5a
JA
11406<B>*</B>
11407
11408have been modified. An argument of
11409<I>n</I>
11410
11411lists only the last
11412<I>n</I>
11413
11414lines.
0001803f
CR
11415If the shell variable
11416<FONT SIZE=-1><B>HISTTIMEFORMAT</B>
11417
11418</FONT>
11419is set and not null,
17345e5a
JA
11420it is used as a format string for <I>strftime</I>(3) to display
11421the time stamp associated with each displayed history entry.
11422No intervening blank is printed between the formatted time stamp
11423and the history line.
11424If <I>filename</I> is supplied, it is used as the
11425name of the history file; if not, the value of
11426<FONT SIZE=-1><B>HISTFILE</B>
11427
11428</FONT>
11429is used. Options, if supplied, have the following meanings:
11430<DL COMPACT><DT><DD>
11431
11432<DL COMPACT>
11433<DT><B>-c</B>
11434
11435<DD>
11436Clear the history list by deleting all the entries.
11437<DT><B>-d</B> <I>offset</I><DD>
11438Delete the history entry at position <I>offset</I>.
d233b485
CR
11439If <I>offset</I> is negative, it is interpreted as relative to one greater
11440than the last history position, so negative indices count back from the
11441end of the history, and an index of -1 refers to the current
11442<B>history -d</B> command.
11443<DT><B>-d</B> <I>start</I>-<I>end</I><DD>
74091dd4
CR
11444Delete the range of history entries between positions <I>start</I> and
11445<I>end</I>, inclusive.
11446Positive and negative values for <I>start</I> and <I>end</I>
d233b485 11447are interpreted as described above.
17345e5a
JA
11448<DT><B>-a</B>
11449
11450<DD>
a0c0a00f
CR
11451Append the ``new'' history lines to the history file.
11452These are history lines entered since the beginning of the current
11453<B>bash</B> session, but not already appended to the history file.
17345e5a
JA
11454<DT><B>-n</B>
11455
11456<DD>
11457Read the history lines not already read from the history
11458file into the current history list. These are lines
11459appended to the history file since the beginning of the
11460current <B>bash</B> session.
11461<DT><B>-r</B>
11462
11463<DD>
11464Read the contents of the history file
ac50fbac 11465and append them to the current history list.
17345e5a
JA
11466<DT><B>-w</B>
11467
11468<DD>
ac50fbac 11469Write the current history list to the history file, overwriting the
17345e5a
JA
11470history file's contents.
11471<DT><B>-p</B>
11472
11473<DD>
11474Perform history substitution on the following <I>args</I> and display
11475the result on the standard output.
11476Does not store the results in the history list.
11477Each <I>arg</I> must be quoted to disable normal history expansion.
11478<DT><B>-s</B>
11479
11480<DD>
11481Store the
11482<I>args</I>
11483
11484in the history list as a single entry. The last command in the
11485history list is removed before the
11486<I>args</I>
11487
11488are added.
11489
11490</DL>
11491<P>
11492
0001803f
CR
11493If the
11494<FONT SIZE=-1><B>HISTTIMEFORMAT</B>
11495
11496</FONT>
11497variable is set, the time stamp information
17345e5a
JA
11498associated with each history entry is written to the history file,
11499marked with the history comment character.
11500When the history file is read, lines beginning with the history
11501comment character followed immediately by a digit are interpreted
a0c0a00f 11502as timestamps for the following history entry.
17345e5a
JA
11503The return value is 0 unless an invalid option is encountered, an
11504error occurs while reading or writing the history file, an invalid
74091dd4 11505<I>offset</I> or range is supplied as an argument to <B>-d</B>, or the
17345e5a
JA
11506history expansion supplied as an argument to <B>-p</B> fails.
11507</DL>
11508
11509<DT><B>jobs</B> [<B>-lnprs</B>] [ <I>jobspec</I> ... ]<DD>
11510
11511<DT><B>jobs</B> <B>-x</B> <I>command</I> [ <I>args</I> ... ]<DD>
11512
11513The first form lists the active jobs. The options have the following
11514meanings:
11515<DL COMPACT><DT><DD>
11516
11517<DL COMPACT>
11518<DT><B>-l</B>
11519
11520<DD>
11521List process IDs
11522in addition to the normal information.
17345e5a
JA
11523<DT><B>-n</B>
11524
11525<DD>
11526Display information only about jobs that have changed status since
11527the user was last notified of their status.
495aee44
CR
11528<DT><B>-p</B>
11529
11530<DD>
11531List only the process ID of the job's process group
11532leader.
17345e5a
JA
11533<DT><B>-r</B>
11534
11535<DD>
ac50fbac 11536Display only running jobs.
17345e5a
JA
11537<DT><B>-s</B>
11538
11539<DD>
ac50fbac 11540Display only stopped jobs.
17345e5a
JA
11541
11542</DL>
11543<P>
11544
11545If
11546<I>jobspec</I>
11547
11548is given, output is restricted to information about that job.
11549The return status is 0 unless an invalid option is encountered
11550or an invalid
11551<I>jobspec</I>
11552
11553is supplied.
11554<P>
11555
11556If the
11557<B>-x</B>
11558
11559option is supplied,
11560<B>jobs</B>
11561
11562replaces any
11563<I>jobspec</I>
11564
11565found in
11566<I>command</I>
11567
11568or
11569<I>args</I>
11570
11571with the corresponding process group ID, and executes
11572<I>command</I>
11573
11574passing it
11575<I>args</I>,
11576
11577returning its exit status.
11578</DL>
11579
11580<DT><B>kill</B> [<B>-s</B> <I>sigspec</I> | <B>-n</B> <I>signum</I> | <B>-</B><I>sigspec</I>] [<I>pid</I> | <I>jobspec</I>] ...<DD>
11581
a0c0a00f 11582<DT><B>kill</B> <B>-l</B>|<B>-L</B> [<I>sigspec</I> | <I>exit_status</I>]<DD>
17345e5a
JA
11583
11584Send the signal named by
11585<I>sigspec</I>
11586
11587or
11588<I>signum</I>
11589
11590to the processes named by
11591<I>pid</I>
11592
11593or
11594<I>jobspec</I>.
11595
11596<I>sigspec</I>
11597
11598is either a case-insensitive signal name such as
11599<FONT SIZE=-1><B>SIGKILL</B>
11600
11601</FONT>
11602(with or without the
11603<FONT SIZE=-1><B>SIG</B>
11604
11605</FONT>
11606prefix) or a signal number;
11607<I>signum</I>
11608
11609is a signal number.
11610If
11611<I>sigspec</I>
11612
11613is not present, then
11614<FONT SIZE=-1><B>SIGTERM</B>
11615
11616</FONT>
11617is assumed.
11618An argument of
11619<B>-l</B>
11620
11621lists the signal names.
11622If any arguments are supplied when
11623<B>-l</B>
11624
11625is given, the names of the signals corresponding to the arguments are
11626listed, and the return status is 0.
11627The <I>exit_status</I> argument to
11628<B>-l</B>
11629
11630is a number specifying either a signal number or the exit status of
11631a process terminated by a signal.
a0c0a00f
CR
11632The
11633<B>-L</B>
11634
11635option is equivalent to <B>-l</B>.
17345e5a
JA
11636<B>kill</B>
11637
11638returns true if at least one signal was successfully sent, or false
11639if an error occurs or an invalid option is encountered.
11640<DT><B>let</B> <I>arg</I> [<I>arg</I> ...]<DD>
11641Each
11642<I>arg</I>
11643
11644is an arithmetic expression to be evaluated (see
0001803f 11645<FONT SIZE=-1><B>ARITHMETIC EVALUATION</B>
17345e5a
JA
11646
11647</FONT>
74091dd4 11648
0001803f 11649above).
17345e5a
JA
11650If the last
11651<I>arg</I>
11652
11653evaluates to 0,
11654<B>let</B>
11655
11656returns 1; 0 is returned otherwise.
a0c0a00f 11657<DT><B>local</B> [<I>option</I>] [<I>name</I>[=<I>value</I>] ... | - ]<DD>
17345e5a 11658For each argument, a local variable named
a0c0a00f 11659<I>name</I>
17345e5a
JA
11660
11661is created, and assigned
11662<I>value</I>.
11663
11664The <I>option</I> can be any of the options accepted by <B>declare</B>.
11665When
11666<B>local</B>
11667
11668is used within a function, it causes the variable
11669<I>name</I>
11670
11671to have a visible scope restricted to that function and its children.
a0c0a00f
CR
11672If <I>name</I> is -, the set of shell options is made local to the function
11673in which <B>local</B> is invoked: shell options changed using the
11674<B>set</B> builtin inside the function are restored to their original values
11675when the function returns.
8868edaf
CR
11676The restore is effected as if a series of <B>set</B> commands were executed
11677to restore the values that were in place before the function.
17345e5a
JA
11678With no operands,
11679<B>local</B>
11680
11681writes a list of local variables to the standard output. It is
11682an error to use
11683<B>local</B>
11684
11685when not within a function. The return status is 0 unless
11686<B>local</B>
11687
11688is used outside a function, an invalid
11689<I>name</I>
11690
11691is supplied, or
11692<I>name</I> is a readonly variable.
11693<DT><B>logout</B>
11694
11695<DD>
11696Exit a login shell.
a0c0a00f 11697<DT><B>mapfile</B> [<B>-d</B> <I>delim</I>] [<B>-n</B> <I>count</I>] [<B>-O</B> <I>origin</I>] [<B>-s</B> <I>count</I>] [<B>-t</B>] [<B>-u</B> <I>fd</I>] [<B>-C</B> <I>callback</I>] [<B>-c</B> <I>quantum</I>] [<I>array</I>]<DD>
17345e5a 11698
a0c0a00f 11699<DT><B>readarray</B> [<B>-d</B> <I>delim</I>] [<B>-n</B> <I>count</I>] [<B>-O</B> <I>origin</I>] [<B>-s</B> <I>count</I>] [<B>-t</B>] [<B>-u</B> <I>fd</I>] [<B>-C</B> <I>callback</I>] [<B>-c</B> <I>quantum</I>] [<I>array</I>]<DD>
17345e5a 11700
0001803f 11701Read lines from the standard input into the indexed array variable
17345e5a
JA
11702<I>array</I>,
11703
a0c0a00f 11704or from file descriptor
17345e5a
JA
11705<I>fd</I>
11706
a0c0a00f 11707if the
17345e5a
JA
11708<B>-u</B>
11709
11710option is supplied.
0001803f
CR
11711The variable
11712<FONT SIZE=-1><B>MAPFILE</B>
11713
11714</FONT>
11715is the default <I>array</I>.
17345e5a
JA
11716Options, if supplied, have the following meanings:
11717<DL COMPACT><DT><DD>
11718
11719<DL COMPACT>
a0c0a00f
CR
11720<DT><B>-d</B>
11721
11722<DD>
11723The first character of <I>delim</I> is used to terminate each input line,
11724rather than newline.
d233b485
CR
11725If <I>delim</I> is the empty string, <B>mapfile</B> will terminate a line
11726when it reads a NUL character.
17345e5a
JA
11727<DT><B>-n</B>
11728
11729<DD>
11730Copy at most
11731<I>count</I>
11732
11733lines. If <I>count</I> is 0, all lines are copied.
11734<DT><B>-O</B>
11735
11736<DD>
11737Begin assigning to
11738<I>array</I>
11739
11740at index
11741<I>origin</I>.
11742
11743The default index is 0.
11744<DT><B>-s</B>
11745
11746<DD>
11747Discard the first <I>count</I> lines read.
11748<DT><B>-t</B>
11749
11750<DD>
a0c0a00f 11751Remove a trailing <I>delim</I> (default newline) from each line read.
17345e5a
JA
11752<DT><B>-u</B>
11753
11754<DD>
11755Read lines from file descriptor <I>fd</I> instead of the standard input.
11756<DT><B>-C</B>
11757
11758<DD>
11759Evaluate
11760<I>callback</I>
11761
11762each time <I>quantum</I> lines are read. The <B>-c</B> option specifies
11763<I>quantum</I>.
11764
11765<DT><B>-c</B>
11766
11767<DD>
11768Specify the number of lines read between each call to
11769<I>callback</I>.
11770
11771
11772</DL>
11773<P>
11774
11775If
11776<B>-C</B>
11777
a0c0a00f 11778is specified without
17345e5a
JA
11779<B>-c</B>,
11780
11781the default quantum is 5000.
11782When <I>callback</I> is evaluated, it is supplied the index of the next
495aee44
CR
11783array element to be assigned and the line to be assigned to that element
11784as additional arguments.
a0c0a00f 11785<I>callback</I> is evaluated after the line is read but before the
17345e5a
JA
11786array element is assigned.
11787<P>
11788
11789If not supplied with an explicit origin, <B>mapfile</B> will clear <I>array</I>
11790before assigning to it.
11791<P>
11792
11793<B>mapfile</B> returns successfully unless an invalid option or option
0001803f
CR
11794argument is supplied, <I>array</I> is invalid or unassignable, or if
11795<I>array</I> is not an indexed array.
17345e5a
JA
11796</DL>
11797
11798<DT><B>popd</B> [-<B>n</B>] [+<I>n</I>] [-<I>n</I>]<DD>
74091dd4
CR
11799Removes entries from the directory stack.
11800The elements are numbered from 0 starting at the first directory
11801listed by <B>dirs</B>.
11802With no arguments, <B>popd</B>
11803removes the top directory from the stack, and
11804changes to the new top directory.
17345e5a
JA
11805Arguments, if supplied, have the following meanings:
11806<DL COMPACT><DT><DD>
11807
11808<DL COMPACT>
11809<DT><B>-n</B>
11810
11811<DD>
11812Suppresses the normal change of directory when removing directories
11813from the stack, so that only the stack is manipulated.
11814<DT><B>+</B><I>n</I><DD>
11815Removes the <I>n</I>th entry counting from the left of the list
11816shown by
11817<B>dirs</B>,
11818
74091dd4
CR
11819starting with zero, from the stack.
11820For example:
17345e5a
JA
11821
11822<TT>popd +0</TT>
11823removes the first directory,
11824
11825<TT>popd +1</TT>
11826the second.
11827<DT><B>-</B><I>n</I><DD>
11828Removes the <I>n</I>th entry counting from the right of the list
11829shown by
11830<B>dirs</B>,
11831
11832starting with zero. For example:
11833
11834<TT>popd -0</TT>
11835removes the last directory,
11836
11837<TT>popd -1</TT>
11838the next to last.
11839
11840</DL>
11841<P>
11842
74091dd4
CR
11843If the top element of the directory stack is modified, and
11844the <I>-n</I> option was not supplied, <B>popd</B> uses the <B>cd</B>
11845builtin to change to the directory at the top of the stack.
11846If the <B>cd</B> fails, <B>popd</B> returns a non-zero value.
11847<P>
11848
11849Otherwise,
17345e5a
JA
11850<B>popd</B>
11851
74091dd4
CR
11852returns false if an invalid option is encountered, the directory stack
11853is empty, or a non-existent directory stack entry is specified.
11854<P>
17345e5a 11855
74091dd4 11856If the
17345e5a
JA
11857<B>popd</B>
11858
74091dd4
CR
11859command is successful,
11860bash runs
11861<B>dirs</B>
11862
11863to show the final contents of the directory stack,
11864and the return status is 0.
17345e5a
JA
11865</DL>
11866
11867<DT><B>printf</B> [<B>-v</B> <I>var</I>] <I>format</I> [<I>arguments</I>]<DD>
11868Write the formatted <I>arguments</I> to the standard output under the
11869control of the <I>format</I>.
495aee44
CR
11870The <B>-v</B> option causes the output to be assigned to the variable
11871<I>var</I> rather than being printed to the standard output.
11872<P>
17345e5a
JA
11873The <I>format</I> is a character string which contains three types of objects:
11874plain characters, which are simply copied to standard output, character
11875escape sequences, which are converted and copied to the standard output, and
11876format specifications, each of which causes printing of the next successive
11877<I>argument</I>.
495aee44
CR
11878In addition to the standard <I>printf</I>(1) format specifications,
11879<B>printf</B> interprets the following extensions:
11880<DL COMPACT><DT><DD>
11881
11882<DL COMPACT>
11883<DT><B>%b</B>
11884
11885<DD>
11886causes
17345e5a 11887<B>printf</B> to expand backslash escape sequences in the corresponding
a0c0a00f
CR
11888<I>argument</I>
11889in the same way as <B>echo -e</B>.
495aee44
CR
11890<DT><B>%q</B>
11891
11892<DD>
11893causes <B>printf</B> to output the corresponding
17345e5a 11894<I>argument</I> in a format that can be reused as shell input.
74091dd4
CR
11895<DT><B>%Q</B>
11896
11897<DD>
11898like <B>%q</B>, but applies any supplied precision to the <I>argument</I>
11899before quoting it.
495aee44
CR
11900<DT><B>%(</B><I>datefmt</I>)T
11901
11902<DD>
11903causes <B>printf</B> to output the date-time string resulting from using
ac50fbac
CR
11904<I>datefmt</I> as a format string for <I>strftime</I>(3).
11905The corresponding <I>argument</I> is an integer representing the number of
11906seconds since the epoch.
11907Two special argument values may be used: -1 represents the current
495aee44 11908time, and -2 represents the time the shell was invoked.
ac50fbac
CR
11909If no argument is specified, conversion behaves as if -1 had been given.
11910This is an exception to the usual <B>printf</B> behavior.
495aee44
CR
11911
11912</DL>
17345e5a 11913<P>
495aee44 11914
8868edaf
CR
11915The %b, %q, and %T directives all use the field width and precision
11916arguments from the format specification and write that many bytes from
11917(or use that wide a field for) the expanded argument, which usually
11918contains more characters than the original.
11919<P>
11920
495aee44
CR
11921Arguments to non-string format specifiers are treated as C constants,
11922except that a leading plus or minus sign is allowed, and if the leading
11923character is a single or double quote, the value is the ASCII value of
11924the following character.
17345e5a 11925<P>
495aee44 11926
17345e5a
JA
11927The <I>format</I> is reused as necessary to consume all of the <I>arguments</I>.
11928If the <I>format</I> requires more <I>arguments</I> than are supplied, the
11929extra format specifications behave as if a zero value or null string, as
495aee44
CR
11930appropriate, had been supplied.
11931The return value is zero on success, non-zero on failure.
11932</DL>
11933
17345e5a
JA
11934<DT><B>pushd</B> [<B>-n</B>] [+<I>n</I>] [-<I>n</I>]<DD>
11935
11936<DT><B>pushd</B> [<B>-n</B>] [<I>dir</I>]<DD>
11937
11938Adds a directory to the top of the directory stack, or rotates
11939the stack, making the new top of the stack the current working
74091dd4
CR
11940directory.
11941With no arguments, <B>pushd</B> exchanges the top two elements of
11942the directory stack.
17345e5a
JA
11943Arguments, if supplied, have the following meanings:
11944<DL COMPACT><DT><DD>
11945
11946<DL COMPACT>
11947<DT><B>-n</B>
11948
11949<DD>
a0c0a00f
CR
11950Suppresses the normal change of directory when rotating or
11951adding directories to the stack, so that only the stack is manipulated.
17345e5a
JA
11952<DT><B>+</B><I>n</I><DD>
11953Rotates the stack so that the <I>n</I>th directory
11954(counting from the left of the list shown by
11955<B>dirs</B>,
11956
11957starting with zero)
11958is at the top.
11959<DT><B>-</B><I>n</I><DD>
11960Rotates the stack so that the <I>n</I>th directory
11961(counting from the right of the list shown by
11962<B>dirs</B>,
11963
11964starting with zero) is at the top.
11965<DT><I>dir</I>
11966
11967<DD>
11968Adds
11969<I>dir</I>
11970
74091dd4 11971to the directory stack at the top
17345e5a
JA
11972
11973</DL>
11974<P>
11975
74091dd4
CR
11976After the stack has been modified, if the <B>-n</B> option was not
11977supplied, <B>pushd</B> uses the <B>cd</B> builtin to change to the
11978directory at the top of the stack.
11979If the <B>cd</B> fails, <B>pushd</B> returns a non-zero value.
11980<P>
17345e5a 11981
74091dd4
CR
11982Otherwise, if no arguments are supplied,
11983<B>pushd</B>
17345e5a 11984
74091dd4
CR
11985returns 0 unless the directory stack is empty.
11986When rotating the directory stack,
17345e5a
JA
11987<B>pushd</B>
11988
74091dd4
CR
11989returns 0 unless the directory stack is empty or
11990a non-existent directory stack element is specified.
11991<P>
17345e5a 11992
74091dd4 11993If the
17345e5a
JA
11994<B>pushd</B>
11995
74091dd4
CR
11996command is successful,
11997bash runs
11998<B>dirs</B>
11999
12000to show the final contents of the directory stack.
17345e5a
JA
12001</DL>
12002
12003<DT><B>pwd</B> [<B>-LP</B>]<DD>
12004Print the absolute pathname of the current working directory.
12005The pathname printed contains no symbolic links if the
12006<B>-P</B>
12007
a0c0a00f 12008option is supplied or the
17345e5a
JA
12009<B>-o physical</B>
12010
12011option to the
12012<B>set</B>
12013
12014builtin command is enabled.
12015If the
12016<B>-L</B>
12017
12018option is used, the pathname printed may contain symbolic links.
12019The return status is 0 unless an error occurs while
12020reading the name of the current directory or an
12021invalid option is supplied.
0001803f 12022<DT><B>read</B> [<B>-ers</B>] [<B>-a</B> <I>aname</I>] [<B>-d</B> <I>delim</I>] [<B>-i</B> <I>text</I>] [<B>-n</B> <I>nchars</I>] [<B>-N</B> <I>nchars</I>] [<B>-p</B> <I>prompt</I>] [<B>-t</B> <I>timeout</I>] [<B>-u</B> <I>fd</I>] [<I>name</I> ...]<DD>
17345e5a 12023One line is read from the standard input, or from the file descriptor
a0c0a00f 12024<I>fd</I> supplied as an argument to the <B>-u</B> option,
74091dd4
CR
12025split into words as described
12026
12027above
12028under <B>Word Splitting</B>,
a0c0a00f 12029and the first word
17345e5a
JA
12030is assigned to the first
12031<I>name</I>,
12032
12033the second word to the second
12034<I>name</I>,
12035
a0c0a00f
CR
12036and so on.
12037If there are more words than names, the remaining words and their
12038intervening delimiters are assigned to the last
17345e5a
JA
12039<I>name</I>.
12040
12041If there are fewer words read from the input stream than names,
12042the remaining names are assigned empty values.
a0c0a00f 12043The characters in
17345e5a
JA
12044<FONT SIZE=-1><B>IFS</B>
12045
12046</FONT>
ac50fbac 12047are used to split the line into words using the same rules the shell
74091dd4
CR
12048uses for expansion (described
12049
12050above
12051under <B>Word Splitting</B>).
17345e5a
JA
12052The backslash character (<B>\</B>) may be used to remove any special
12053meaning for the next character read and for line continuation.
12054Options, if supplied, have the following meanings:
12055<DL COMPACT><DT><DD>
12056
12057<DL COMPACT>
12058<DT><B>-a </B><I>aname</I>
12059
12060<DD>
12061The words are assigned to sequential indices
12062of the array variable
12063<I>aname</I>,
12064
12065starting at 0.
12066<I>aname</I>
12067
12068is unset before any new values are assigned.
12069Other <I>name</I> arguments are ignored.
12070<DT><B>-d </B><I>delim</I>
12071
12072<DD>
12073The first character of <I>delim</I> is used to terminate the input line,
12074rather than newline.
d233b485
CR
12075If <I>delim</I> is the empty string, <B>read</B> will terminate a line
12076when it reads a NUL character.
17345e5a
JA
12077<DT><B>-e</B>
12078
12079<DD>
12080If the standard input
12081is coming from a terminal,
12082<B>readline</B>
12083
12084(see
12085<FONT SIZE=-1><B>READLINE</B>
12086
12087</FONT>
74091dd4
CR
12088
12089above)
12090is used to obtain the line.
17345e5a 12091Readline uses the current (or default, if line editing was not previously
74091dd4 12092active) editing settings, but uses readline's default filename completion.
17345e5a
JA
12093<DT><B>-i </B><I>text</I>
12094
12095<DD>
12096If
12097<B>readline</B>
12098
12099is being used to read the line, <I>text</I> is placed into the editing
12100buffer before editing begins.
12101<DT><B>-n </B><I>nchars</I>
12102
12103<DD>
12104<B>read</B> returns after reading <I>nchars</I> characters rather than
a0c0a00f 12105waiting for a complete line of input, but honors a delimiter if fewer
0001803f
CR
12106than <I>nchars</I> characters are read before the delimiter.
12107<DT><B>-N </B><I>nchars</I>
12108
12109<DD>
12110<B>read</B> returns after reading exactly <I>nchars</I> characters rather
12111than waiting for a complete line of input, unless EOF is encountered or
12112<B>read</B> times out.
12113Delimiter characters encountered in the input are
12114not treated specially and do not cause <B>read</B> to return until
12115<I>nchars</I> characters are read.
a0c0a00f
CR
12116The result is not split on the characters in <B>IFS</B>; the intent is
12117that the variable is assigned exactly the characters read
12118(with the exception of backslash; see the <B>-r</B> option below).
17345e5a
JA
12119<DT><B>-p </B><I>prompt</I>
12120
12121<DD>
12122Display <I>prompt</I> on standard error, without a
12123trailing newline, before attempting to read any input. The prompt
12124is displayed only if input is coming from a terminal.
12125<DT><B>-r</B>
12126
12127<DD>
12128Backslash does not act as an escape character.
12129The backslash is considered to be part of the line.
d233b485 12130In particular, a backslash-newline pair may not then be used as a line
17345e5a
JA
12131continuation.
12132<DT><B>-s</B>
12133
12134<DD>
12135Silent mode. If input is coming from a terminal, characters are
12136not echoed.
12137<DT><B>-t </B><I>timeout</I>
12138
12139<DD>
12140Cause <B>read</B> to time out and return failure if a complete line of
ac50fbac
CR
12141input (or a specified number of characters)
12142is not read within <I>timeout</I> seconds.
17345e5a
JA
12143<I>timeout</I> may be a decimal number with a fractional portion following
12144the decimal point.
12145This option is only effective if <B>read</B> is reading input from a
12146terminal, pipe, or other special file; it has no effect when reading
12147from regular files.
ac50fbac
CR
12148If <B>read</B> times out, <B>read</B> saves any partial input read into
12149the specified variable <I>name</I>.
12150If <I>timeout</I> is 0, <B>read</B> returns immediately, without trying to
74091dd4
CR
12151read any data.
12152The exit status is 0 if input is available on the specified file descriptor,
12153or the read will return EOF,
12154non-zero otherwise.
17345e5a
JA
12155The exit status is greater than 128 if the timeout is exceeded.
12156<DT><B>-u </B><I>fd</I>
12157
12158<DD>
12159Read input from file descriptor <I>fd</I>.
12160
12161</DL>
12162<P>
12163
12164If no
12165<I>names</I>
12166
8868edaf
CR
12167are supplied, the line read,
12168without the ending delimiter but otherwise unmodified,
12169is assigned to the variable
17345e5a
JA
12170<FONT SIZE=-1><B>REPLY</B>.
12171
12172</FONT>
a0c0a00f
CR
12173The exit status is zero, unless end-of-file is encountered, <B>read</B>
12174times out (in which case the status is greater than 128),
ac50fbac
CR
12175a variable assignment error (such as assigning to a readonly variable) occurs,
12176or an invalid file descriptor is supplied as the argument to <B>-u</B>.
17345e5a
JA
12177</DL>
12178
ac50fbac 12179<DT><B>readonly</B> [<B>-aAf</B>] [<B>-p</B>] [<I>name</I>[=<I>word</I>] ...]<DD>
17345e5a
JA
12180
12181The given
12182<I>names</I> are marked readonly; the values of these
12183<I>names</I>
12184
12185may not be changed by subsequent assignment.
12186If the
12187<B>-f</B>
12188
12189option is supplied, the functions corresponding to the
12190<I>names</I> are so
12191marked.
12192The
12193<B>-a</B>
12194
12195option restricts the variables to indexed arrays; the
12196<B>-A</B>
12197
12198option restricts the variables to associative arrays.
ac50fbac
CR
12199If both options are supplied,
12200<B>-A</B>
12201
12202takes precedence.
17345e5a
JA
12203If no
12204<I>name</I>
12205
12206arguments are given, or if the
12207<B>-p</B>
12208
12209option is supplied, a list of all readonly names is printed.
ac50fbac
CR
12210The other options may be used to restrict the output to a subset of
12211the set of readonly names.
17345e5a
JA
12212The
12213<B>-p</B>
12214
12215option causes output to be displayed in a format that
12216may be reused as input.
12217If a variable name is followed by =<I>word</I>, the value of
12218the variable is set to <I>word</I>.
12219The return status is 0 unless an invalid option is encountered,
12220one of the
12221<I>names</I>
12222
12223is not a valid shell variable name, or
12224<B>-f</B>
12225
12226is supplied with a
12227<I>name</I>
12228
12229that is not a function.
12230<DT><B>return</B> [<I>n</I>]<DD>
ac50fbac
CR
12231Causes a function to stop executing and return the value specified by
12232<I>n</I>
17345e5a 12233
ac50fbac 12234to its caller.
a0c0a00f 12235If
17345e5a
JA
12236<I>n</I>
12237
12238is omitted, the return status is that of the last command
a0c0a00f
CR
12239executed in the function body.
12240If <B>return</B> is executed by a trap handler, the last command used to
12241determine the status is the last command executed before the trap handler.
d233b485 12242If <B>return</B> is executed during a <B>DEBUG</B> trap, the last command
a0c0a00f
CR
12243used to determine the status is the last command executed by the trap
12244handler before <B>return</B> was invoked.
12245If
ac50fbac
CR
12246<B>return</B>
12247
12248is used outside a function,
a0c0a00f 12249but during execution of a script by the
17345e5a
JA
12250<B>.</B>
12251
12252(<B>source</B>) command, it causes the shell to stop executing
12253that script and return either
12254<I>n</I>
12255
12256or the exit status of the last command executed within the
ac50fbac
CR
12257script as the exit status of the script.
12258If <I>n</I> is supplied, the return value is its least significant
122598 bits.
12260The return status is non-zero if
12261<B>return</B>
12262
12263is supplied a non-numeric argument, or
12264is used outside a
12265function and not during execution of a script by <B>.</B> or <B>source</B>.
17345e5a
JA
12266Any command associated with the <B>RETURN</B> trap is executed
12267before execution resumes after the function or script.
74091dd4 12268<DT><B>set</B> [<B>-abefhkmnptuvxBCEHPT</B>] [<B>-o</B> <I>option-name</I>] [<B>--</B>] [<B>-</B>] [<I>arg</I> ...]<DD>
17345e5a 12269
74091dd4 12270<DT><B>set</B> [<B>+abefhkmnptuvxBCEHPT</B>] [<B>+o</B> <I>option-name</I>] [<B>--</B>] [<B>-</B>] [<I>arg</I> ...]<DD>
17345e5a 12271
74091dd4 12272Without options, display the name and value of each shell variable
17345e5a
JA
12273in a format that can be reused as input
12274for setting or resetting the currently-set variables.
12275Read-only variables cannot be reset.
d233b485 12276In <I>posix mode</I>, only shell variables are listed.
17345e5a
JA
12277The output is sorted according to the current locale.
12278When options are specified, they set or unset shell attributes.
12279Any arguments remaining after option processing are treated
a0c0a00f 12280as values for the positional parameters and are assigned, in order, to
17345e5a
JA
12281<B>$1</B>,
12282
12283<B>$2</B>,
12284
12285<B>...</B>
12286
12287<B>$</B><I>n</I>.
12288
12289Options, if specified, have the following meanings:
12290<DL COMPACT><DT><DD>
12291
12292<DL COMPACT>
12293<DT><B>-a</B>
12294
12295<DD>
a0c0a00f
CR
12296Each variable or function that is created or modified is given the
12297export attribute and marked for export to the environment of
12298subsequent commands.
17345e5a
JA
12299<DT><B>-b</B>
12300
12301<DD>
12302Report the status of terminated background jobs
12303immediately, rather than before the next primary prompt. This is
12304effective only when job control is enabled.
12305<DT><B>-e</B>
12306
12307<DD>
ac50fbac
CR
12308Exit immediately if a
12309<I>pipeline</I> (which may consist of a single <I>simple command</I>),
12310a <I>list</I>,
12311or a <I>compound command</I>
12312(see
17345e5a
JA
12313<FONT SIZE=-1><B>SHELL GRAMMAR</B>
12314
12315</FONT>
74091dd4
CR
12316
12317above),
12318exits with a non-zero status.
17345e5a
JA
12319The shell does not exit if the
12320command that fails is part of the command list immediately following a
12321<B>while</B>
12322
12323or
12324<B>until</B>
12325
a0c0a00f 12326keyword,
0001803f 12327part of the test following the
17345e5a
JA
12328<B>if</B>
12329
0001803f
CR
12330or
12331<B>elif</B>
12332
12333reserved words, part of any command executed in a
17345e5a
JA
12334<B>&amp;&amp;</B>
12335
12336or
12337<B>||</B>
12338
0001803f 12339list except the command following the final <B>&amp;&amp;</B> or <B>||</B>,
17345e5a
JA
12340any command in a pipeline but the last,
12341or if the command's return value is
0001803f 12342being inverted with
17345e5a
JA
12343<B>!</B>.
12344
ac50fbac
CR
12345If a compound command other than a subshell
12346returns a non-zero status because a command failed
12347while <B>-e</B> was being ignored, the shell does not exit.
17345e5a 12348A trap on <B>ERR</B>, if set, is executed before the shell exits.
0001803f
CR
12349This option applies to the shell environment and each subshell environment
12350separately (see
12351<FONT SIZE=-1><B>COMMAND EXECUTION ENVIRONMENT</B>
12352
12353</FONT>
74091dd4
CR
12354
12355above),
12356and may cause
0001803f 12357subshells to exit before executing all the commands in the subshell.
ac50fbac
CR
12358<P>
12359
12360
12361If a compound command or shell function executes in a context
12362where <B>-e</B> is being ignored,
12363none of the commands executed within the compound command or function body
12364will be affected by the <B>-e</B> setting, even if <B>-e</B> is set
12365and a command returns a failure status.
12366If a compound command or shell function sets <B>-e</B> while executing in
12367a context where <B>-e</B> is ignored, that setting will not have any
12368effect until the compound command or the command containing the function
12369call completes.
17345e5a
JA
12370<DT><B>-f</B>
12371
12372<DD>
12373Disable pathname expansion.
12374<DT><B>-h</B>
12375
12376<DD>
12377Remember the location of commands as they are looked up for execution.
12378This is enabled by default.
12379<DT><B>-k</B>
12380
12381<DD>
12382All arguments in the form of assignment statements
12383are placed in the environment for a command, not just
12384those that precede the command name.
12385<DT><B>-m</B>
12386
12387<DD>
12388Monitor mode. Job control is enabled. This option is on
12389by default for interactive shells on systems that support
12390it (see
12391<FONT SIZE=-1><B>JOB CONTROL</B>
12392
12393</FONT>
74091dd4 12394
ac50fbac
CR
12395above).
12396All processes run in a separate process group.
12397When a background job completes, the shell prints a line
12398containing its exit status.
17345e5a
JA
12399<DT><B>-n</B>
12400
12401<DD>
a0c0a00f
CR
12402Read commands but do not execute them.
12403This may be used to check a shell script for syntax errors.
12404This is ignored by interactive shells.
17345e5a
JA
12405<DT><B>-o </B><I>option-name</I>
12406
12407<DD>
12408The <I>option-name</I> can be one of the following:
12409<DL COMPACT><DT><DD>
12410<DL COMPACT>
12411<DT><B>allexport</B>
12412
12413<DD>
12414Same as
12415<B>-a</B>.
12416
12417<DT><B>braceexpand</B>
12418
12419<DD>
12420Same as
12421<B>-B</B>.
12422
12423<DT><B>emacs</B>
12424
12425<DD>
12426Use an emacs-style command line editing interface. This is enabled
12427by default when the shell is interactive, unless the shell is started
12428with the
12429<B>--noediting</B>
12430
12431option.
12432This also affects the editing interface used for <B>read -e</B>.
0001803f 12433<DT><B>errexit</B>
17345e5a
JA
12434
12435<DD>
12436Same as
0001803f 12437<B>-e</B>.
17345e5a 12438
0001803f 12439<DT><B>errtrace</B>
17345e5a
JA
12440
12441<DD>
12442Same as
0001803f 12443<B>-E</B>.
17345e5a 12444
0001803f 12445<DT><B>functrace</B>
17345e5a
JA
12446
12447<DD>
12448Same as
0001803f 12449<B>-T</B>.
17345e5a
JA
12450
12451<DT><B>hashall</B>
12452
12453<DD>
12454Same as
12455<B>-h</B>.
12456
12457<DT><B>histexpand</B>
12458
12459<DD>
12460Same as
12461<B>-H</B>.
12462
12463<DT><B>history</B>
12464
12465<DD>
74091dd4
CR
12466Enable command history, as described
12467
12468above
12469under
17345e5a
JA
12470<FONT SIZE=-1><B>HISTORY</B>.
12471
12472</FONT>
12473This option is on by default in interactive shells.
12474<DT><B>ignoreeof</B>
12475
12476<DD>
12477The effect is as if the shell command
12478<TT>IGNOREEOF=10</TT>
12479
12480had been executed
12481(see
12482<B>Shell Variables</B>
12483
74091dd4 12484
17345e5a
JA
12485above).
12486<DT><B>keyword</B>
12487
12488<DD>
12489Same as
12490<B>-k</B>.
12491
12492<DT><B>monitor</B>
12493
12494<DD>
12495Same as
12496<B>-m</B>.
12497
12498<DT><B>noclobber</B>
12499
12500<DD>
12501Same as
12502<B>-C</B>.
12503
12504<DT><B>noexec</B>
12505
12506<DD>
12507Same as
12508<B>-n</B>.
12509
12510<DT><B>noglob</B>
12511
12512<DD>
12513Same as
12514<B>-f</B>.
12515
12516<DT><B>nolog</B>
12517
12518<DD>
12519Currently ignored.
12520<DT><B>notify</B>
12521
12522<DD>
12523Same as
12524<B>-b</B>.
12525
12526<DT><B>nounset</B>
12527
12528<DD>
12529Same as
12530<B>-u</B>.
12531
12532<DT><B>onecmd</B>
12533
12534<DD>
12535Same as
12536<B>-t</B>.
12537
12538<DT><B>physical</B>
12539
12540<DD>
12541Same as
12542<B>-P</B>.
12543
12544<DT><B>pipefail</B>
12545
12546<DD>
12547If set, the return value of a pipeline is the value of the last
12548(rightmost) command to exit with a non-zero status, or zero if all
12549commands in the pipeline exit successfully.
12550This option is disabled by default.
12551<DT><B>posix</B>
12552
12553<DD>
12554Change the behavior of
12555<B>bash</B>
12556
12557where the default operation differs
12558from the POSIX standard to match the standard (<I>posix mode</I>).
ac50fbac
CR
12559See
12560<FONT SIZE=-1><B>SEE ALSO</B>
12561
12562</FONT>
74091dd4
CR
12563
12564below
12565for a reference to a document that details how posix mode affects
ac50fbac 12566bash's behavior.
17345e5a
JA
12567<DT><B>privileged</B>
12568
12569<DD>
12570Same as
12571<B>-p</B>.
12572
12573<DT><B>verbose</B>
12574
12575<DD>
12576Same as
12577<B>-v</B>.
12578
12579<DT><B>vi</B>
12580
12581<DD>
12582Use a vi-style command line editing interface.
12583This also affects the editing interface used for <B>read -e</B>.
12584<DT><B>xtrace</B>
12585
12586<DD>
12587Same as
12588<B>-x</B>.
12589
12590<P>
12591</DL>
12592<P>
12593
12594If
12595<B>-o</B>
12596
12597is supplied with no <I>option-name</I>, the values of the current options are
12598printed.
12599If
12600<B>+o</B>
12601
12602is supplied with no <I>option-name</I>, a series of
12603<B>set</B>
12604
12605commands to recreate the current option settings is displayed on
12606the standard output.
12607</DL>
12608
12609<DT><B>-p</B>
12610
12611<DD>
12612Turn on
12613<I>privileged</I>
12614
12615mode. In this mode, the
12616<FONT SIZE=-1><B>$ENV</B>
12617
12618</FONT>
12619and
12620<FONT SIZE=-1><B>$BASH_ENV</B>
12621
12622</FONT>
12623files are not processed, shell functions are not inherited from the
12624environment, and the
12625<FONT SIZE=-1><B>SHELLOPTS</B>,
12626
12627</FONT>
0001803f
CR
12628<FONT SIZE=-1><B>BASHOPTS</B>,
12629
12630</FONT>
12631<FONT SIZE=-1><B>CDPATH</B>,
17345e5a 12632
0001803f 12633</FONT>
17345e5a 12634and
0001803f 12635<FONT SIZE=-1><B>GLOBIGNORE</B>
17345e5a 12636
0001803f 12637</FONT>
17345e5a
JA
12638variables, if they appear in the environment, are ignored.
12639If the shell is started with the effective user (group) id not equal to the
12640real user (group) id, and the <B>-p</B> option is not supplied, these actions
12641are taken and the effective user id is set to the real user id.
12642If the <B>-p</B> option is supplied at startup, the effective user id is
12643not reset.
12644Turning this option off causes the effective user
12645and group ids to be set to the real user and group ids.
74091dd4
CR
12646<DT><B>-r</B>
12647
12648<DD>
12649Enable restricted shell mode.
12650This option cannot be unset once it has been set.
17345e5a
JA
12651<DT><B>-t</B>
12652
12653<DD>
12654Exit after reading and executing one command.
12655<DT><B>-u</B>
12656
12657<DD>
0001803f 12658Treat unset variables and parameters other than the special
74091dd4
CR
12659parameters &quot;@&quot; and &quot;*&quot;,
12660or array variables subscripted with &quot;@&quot; or &quot;*&quot;,
12661as an error when performing
17345e5a 12662parameter expansion. If expansion is attempted on an
0001803f 12663unset variable or parameter, the shell prints an error message, and,
17345e5a
JA
12664if not interactive, exits with a non-zero status.
12665<DT><B>-v</B>
12666
12667<DD>
12668Print shell input lines as they are read.
12669<DT><B>-x</B>
12670
12671<DD>
12672After expanding each <I>simple command</I>,
12673<B>for</B> command, <B>case</B> command, <B>select</B> command, or
12674arithmetic <B>for</B> command, display the expanded value of
12675<FONT SIZE=-1><B>PS4</B>,
12676
12677</FONT>
12678followed by the command and its expanded arguments
12679or associated word list.
12680<DT><B>-B</B>
12681
12682<DD>
12683The shell performs brace expansion (see
12684<B>Brace Expansion</B>
12685
74091dd4
CR
12686
12687above).
12688This is on by default.
17345e5a
JA
12689<DT><B>-C</B>
12690
12691<DD>
12692If set,
12693<B>bash</B>
12694
12695does not overwrite an existing file with the
12696<B>&gt;</B>,
12697
12698<B>&gt;&amp;</B>,
12699
12700and
12701<B>&lt;&gt;</B>
12702
a0c0a00f 12703redirection operators. This may be overridden when
17345e5a
JA
12704creating output files by using the redirection operator
12705<B>&gt;|</B>
12706
12707instead of
12708<B>&gt;</B>.
12709
12710<DT><B>-E</B>
12711
12712<DD>
12713If set, any trap on <B>ERR</B> is inherited by shell functions, command
12714substitutions, and commands executed in a subshell environment.
12715The <B>ERR</B> trap is normally not inherited in such cases.
12716<DT><B>-H</B>
12717
12718<DD>
12719Enable
12720<B>!</B>
12721
12722style history substitution. This option is on by
12723default when the shell is interactive.
12724<DT><B>-P</B>
12725
12726<DD>
ac50fbac 12727If set, the shell does not resolve symbolic links when executing
17345e5a
JA
12728commands such as
12729<B>cd</B>
12730
12731that change the current working directory. It uses the
12732physical directory structure instead. By default,
12733<B>bash</B>
12734
12735follows the logical chain of directories when performing commands
12736which change the current directory.
12737<DT><B>-T</B>
12738
12739<DD>
12740If set, any traps on <B>DEBUG</B> and <B>RETURN</B> are inherited by shell
12741functions, command substitutions, and commands executed in a
12742subshell environment.
12743The <B>DEBUG</B> and <B>RETURN</B> traps are normally not inherited
12744in such cases.
12745<DT><B>--</B>
12746
12747<DD>
12748If no arguments follow this option, then the positional parameters are
12749unset. Otherwise, the positional parameters are set to the
12750<I>arg</I>s, even if some of them begin with a
12751<B>-</B>.
12752
12753<DT><B>-</B>
12754
12755<DD>
12756Signal the end of options, cause all remaining <I>arg</I>s to be
12757assigned to the positional parameters. The
12758<B>-x</B>
12759
12760and
12761<B>-v</B>
12762
12763options are turned off.
12764If there are no <I>arg</I>s,
12765the positional parameters remain unchanged.
12766
12767</DL>
12768<P>
12769
12770The options are off by default unless otherwise noted.
12771Using + rather than - causes these options to be turned off.
12772The options can also be specified as arguments to an invocation of
12773the shell.
12774The current set of options may be found in
12775<B>$-</B>.
12776
12777The return status is always true unless an invalid option is encountered.
12778</DL>
12779
12780<DT><B>shift</B> [<I>n</I>]<DD>
12781The positional parameters from <I>n</I>+1 ... are renamed to
12782<B>$1</B>
12783
12784<B>....</B>
12785
12786Parameters represented by the numbers <B>$#</B>
12787down to <B>$#</B>-<I>n</I>+1 are unset.
12788<I>n</I>
12789
12790must be a non-negative number less than or equal to <B>$#</B>.
12791If
12792<I>n</I>
12793
12794is 0, no parameters are changed.
12795If
a0c0a00f 12796<I>n</I>
17345e5a
JA
12797
12798is not given, it is assumed to be 1.
12799If
12800<I>n</I>
12801
12802is greater than <B>$#</B>, the positional parameters are not changed.
12803The return status is greater than zero if
12804<I>n</I>
12805
12806is greater than
12807<B>$#</B>
12808
12809or less than zero; otherwise 0.
12810<DT><B>shopt</B> [<B>-pqsu</B>] [<B>-o</B>] [<I>optname</I> ...]<DD>
ac50fbac
CR
12811Toggle the values of settings controlling optional shell behavior.
12812The settings can be either those listed below, or, if the
12813<B>-o</B>
12814
12815option is used, those available with the
12816<B>-o</B>
12817
12818option to the <B>set</B> builtin command.
17345e5a
JA
12819With no options, or with the
12820<B>-p</B>
12821
12822option, a list of all settable options is displayed, with
d233b485
CR
12823an indication of whether or not each is set;
12824if <I>optnames</I> are supplied, the output is restricted to those options.
17345e5a
JA
12825The <B>-p</B> option causes output to be displayed in a form that
12826may be reused as input.
12827Other options have the following meanings:
12828<DL COMPACT><DT><DD>
12829
12830<DL COMPACT>
12831<DT><B>-s</B>
12832
12833<DD>
12834Enable (set) each <I>optname</I>.
12835<DT><B>-u</B>
12836
12837<DD>
12838Disable (unset) each <I>optname</I>.
12839<DT><B>-q</B>
12840
12841<DD>
12842Suppresses normal output (quiet mode); the return status indicates
12843whether the <I>optname</I> is set or unset.
12844If multiple <I>optname</I> arguments are given with
12845<B>-q</B>,
12846
12847the return status is zero if all <I>optnames</I> are enabled; non-zero
12848otherwise.
12849<DT><B>-o</B>
12850
12851<DD>
12852Restricts the values of <I>optname</I> to be those defined for the
12853<B>-o</B>
12854
12855option to the
12856<B>set</B>
12857
12858builtin.
12859
12860</DL>
12861<P>
12862
12863If either
12864<B>-s</B>
12865
12866or
12867<B>-u</B>
12868
ac50fbac
CR
12869is used with no <I>optname</I> arguments,
12870<B>shopt</B>
12871
12872shows only those options which are set or unset, respectively.
17345e5a
JA
12873Unless otherwise noted, the <B>shopt</B> options are disabled (unset)
12874by default.
12875<P>
12876
12877The return status when listing options is zero if all <I>optnames</I>
12878are enabled, non-zero otherwise. When setting or unsetting options,
12879the return status is zero unless an <I>optname</I> is not a valid shell
12880option.
12881<P>
12882
12883The list of <B>shopt</B> options is:
12884<P>
12885
12886
12887
12888<DL COMPACT>
d233b485
CR
12889<DT><B>assoc_expand_once</B>
12890
12891<DD>
12892If set, the shell suppresses multiple evaluation of associative array
12893subscripts during arithmetic expression evaluation, while executing
12894builtins that can perform variable assignments,
12895and while executing builtins that perform array dereferencing.
17345e5a
JA
12896<DT><B>autocd</B>
12897
12898<DD>
12899If set, a command name that is the name of a directory is executed as if
12900it were the argument to the <B>cd</B> command.
12901This option is only used by interactive shells.
12902<DT><B>cdable_vars</B>
12903
12904<DD>
12905If set, an argument to the
12906<B>cd</B>
12907
12908builtin command that
12909is not a directory is assumed to be the name of a variable whose
12910value is the directory to change to.
12911<DT><B>cdspell</B>
12912
12913<DD>
12914If set, minor errors in the spelling of a directory component in a
12915<B>cd</B>
12916
12917command will be corrected.
12918The errors checked for are transposed characters,
12919a missing character, and one character too many.
ac50fbac 12920If a correction is found, the corrected filename is printed,
17345e5a
JA
12921and the command proceeds.
12922This option is only used by interactive shells.
12923<DT><B>checkhash</B>
12924
12925<DD>
12926If set, <B>bash</B> checks that a command found in the hash
12927table exists before trying to execute it. If a hashed command no
12928longer exists, a normal path search is performed.
12929<DT><B>checkjobs</B>
12930
12931<DD>
12932If set, <B>bash</B> lists the status of any stopped and running jobs before
12933exiting an interactive shell. If any jobs are running, this causes
12934the exit to be deferred until a second exit is attempted without an
0001803f
CR
12935intervening command (see
12936<FONT SIZE=-1><B>JOB CONTROL</B>
12937
12938</FONT>
74091dd4
CR
12939
12940above).
12941The shell always postpones exiting if any jobs are stopped.
17345e5a
JA
12942<DT><B>checkwinsize</B>
12943
12944<DD>
d233b485
CR
12945If set, <B>bash</B> checks the window size after each external (non-builtin)
12946command and, if necessary, updates the values of
17345e5a
JA
12947<FONT SIZE=-1><B>LINES</B>
12948
12949</FONT>
12950and
12951<FONT SIZE=-1><B>COLUMNS</B>.
12952
12953</FONT>
d233b485 12954This option is enabled by default.
17345e5a
JA
12955<DT><B>cmdhist</B>
12956
12957<DD>
12958If set,
12959<B>bash</B>
12960
12961attempts to save all lines of a multiple-line
12962command in the same history entry. This allows
12963easy re-editing of multi-line commands.
d233b485 12964This option is enabled by default, but only has an effect if command
74091dd4
CR
12965history is enabled, as described
12966
12967above
12968under
d233b485
CR
12969<FONT SIZE=-1><B>HISTORY</B>.
12970
12971</FONT>
8868edaf 12972
17345e5a
JA
12973<DT><B>compat31</B>
12974
12975<DD>
ac50fbac
CR
12976<DT><B>compat32</B>
12977
12978<DD>
0001803f
CR
12979<DT><B>compat40</B>
12980
12981<DD>
495aee44
CR
12982<DT><B>compat41</B>
12983
12984<DD>
ac50fbac
CR
12985<DT><B>compat42</B>
12986
12987<DD>
a0c0a00f
CR
12988<DT><B>compat43</B>
12989
12990<DD>
d233b485
CR
12991<DT><B>compat44</B>
12992
74091dd4
CR
12993<DD>
12994<DT><B>compat50</B>
12995
d233b485 12996<DD>
d233b485 12997
8868edaf
CR
12998These control aspects of the shell's compatibility mode
12999(see
13000<FONT SIZE=-1><B>SHELL COMPATIBILITY MODE</B>
13001
13002</FONT>
74091dd4 13003
8868edaf 13004below).
ac50fbac
CR
13005<DT><B>complete_fullquote</B>
13006
13007<DD>
13008If set,
13009<B>bash</B>
13010
13011quotes all shell metacharacters in filenames and directory names when
13012performing completion.
13013If not set,
13014<B>bash</B>
13015
13016removes metacharacters such as the dollar sign from the set of
13017characters that will be quoted in completed filenames
13018when these metacharacters appear in shell variable references in words to be
13019completed.
13020This means that dollar signs in variable names that expand to directories
13021will not be quoted;
13022however, any dollar signs appearing in filenames will not be quoted, either.
13023This is active only when bash is using backslashes to quote completed
13024filenames.
13025This variable is set by default, which is the default bash behavior in
13026versions through 4.2.
13027<DT><B>direxpand</B>
13028
13029<DD>
13030If set,
13031<B>bash</B>
13032
13033replaces directory names with the results of word expansion when performing
13034filename completion. This changes the contents of the readline editing
13035buffer.
13036If not set,
13037<B>bash</B>
13038
13039attempts to preserve what the user typed.
17345e5a
JA
13040<DT><B>dirspell</B>
13041
13042<DD>
13043If set,
13044<B>bash</B>
13045
13046attempts spelling correction on directory names during word completion
13047if the directory name initially supplied does not exist.
13048<DT><B>dotglob</B>
13049
13050<DD>
a0c0a00f 13051If set,
17345e5a
JA
13052<B>bash</B>
13053
13054includes filenames beginning with a `.' in the results of pathname
13055expansion.
d233b485
CR
13056The filenames
13057<B>``.''</B>
13058
13059and
13060<B>``..''</B>
13061
13062must always be matched explicitly, even if
13063<B>dotglob</B>
13064
13065is set.
17345e5a
JA
13066<DT><B>execfail</B>
13067
13068<DD>
13069If set, a non-interactive shell will not exit if
13070it cannot execute the file specified as an argument to the
13071<B>exec</B>
13072
13073builtin command. An interactive shell does not exit if
13074<B>exec</B>
13075
13076fails.
13077<DT><B>expand_aliases</B>
13078
13079<DD>
74091dd4
CR
13080If set, aliases are expanded as described
13081
13082above
13083under
17345e5a
JA
13084<FONT SIZE=-1><B>ALIASES</B>.
13085
13086</FONT>
13087This option is enabled by default for interactive shells.
13088<DT><B>extdebug</B>
13089
13090<DD>
8868edaf
CR
13091If set at shell invocation,
13092or in a shell startup file,
13093arrange to execute the debugger profile
a0c0a00f
CR
13094before the shell starts, identical to the <B>--debugger</B> option.
13095If set after invocation, behavior intended for use by debuggers is enabled:
17345e5a
JA
13096<DL COMPACT><DT><DD>
13097<DL COMPACT>
13098<DT><B>1.</B>
13099
13100<DD>
13101The <B>-F</B> option to the <B>declare</B> builtin displays the source
13102file name and line number corresponding to each function name supplied
13103as an argument.
13104<DT><B>2.</B>
13105
13106<DD>
13107If the command run by the <B>DEBUG</B> trap returns a non-zero value, the
13108next command is skipped and not executed.
13109<DT><B>3.</B>
13110
13111<DD>
13112If the command run by the <B>DEBUG</B> trap returns a value of 2, and the
13113shell is executing in a subroutine (a shell function or a shell script
a0c0a00f
CR
13114executed by the <B>.</B> or <B>source</B> builtins), the shell simulates
13115a call to <B>return</B>.
17345e5a
JA
13116<DT><B>4.</B>
13117
13118<DD>
0001803f
CR
13119<FONT SIZE=-1><B>BASH_ARGC</B>
13120
13121</FONT>
13122and
13123<FONT SIZE=-1><B>BASH_ARGV</B>
13124
13125</FONT>
74091dd4
CR
13126are updated as described in their descriptions
13127
13128above).
17345e5a
JA
13129<DT><B>5.</B>
13130
13131<DD>
a0c0a00f 13132Function tracing is enabled: command substitution, shell functions, and
17345e5a
JA
13133subshells invoked with <B>(</B> <I>command</I> <B>)</B> inherit the
13134<B>DEBUG</B> and <B>RETURN</B> traps.
13135<DT><B>6.</B>
13136
13137<DD>
a0c0a00f 13138Error tracing is enabled: command substitution, shell functions, and
17345e5a 13139subshells invoked with <B>(</B> <I>command</I> <B>)</B> inherit the
495aee44 13140<B>ERR</B> trap.
17345e5a
JA
13141</DL></DL>
13142
13143<DT><B>extglob</B>
13144
13145<DD>
74091dd4
CR
13146If set, the extended pattern matching features described
13147
13148above
13149under
17345e5a
JA
13150<B>Pathname Expansion</B> are enabled.
13151<DT><B>extquote</B>
13152
13153<DD>
13154If set, <B>$</B>aq<I>string</I>aq and <B>$</B>&quot;<I>string</I>&quot; quoting is
13155performed within <B>${</B><I>parameter</I><B>}</B> expansions
13156enclosed in double quotes. This option is enabled by default.
13157<DT><B>failglob</B>
13158
13159<DD>
13160If set, patterns which fail to match filenames during pathname expansion
13161result in an expansion error.
13162<DT><B>force_fignore</B>
13163
13164<DD>
0001803f
CR
13165If set, the suffixes specified by the
13166<FONT SIZE=-1><B>FIGNORE</B>
13167
13168</FONT>
13169shell variable
17345e5a
JA
13170cause words to be ignored when performing word completion even if
13171the ignored words are the only possible completions.
13172See
13173<FONT SIZE=-1><B>SHELL VARIABLES</B></FONT>
74091dd4
CR
13174
13175above
13176for a description of
0001803f
CR
13177<FONT SIZE=-1><B>FIGNORE</B>.
13178
13179</FONT>
17345e5a 13180This option is enabled by default.
ac50fbac
CR
13181<DT><B>globasciiranges</B>
13182
13183<DD>
13184If set, range expressions used in pattern matching bracket expressions (see
13185<FONT SIZE=-1><B>Pattern Matching</B>
13186
13187</FONT>
74091dd4
CR
13188
13189above)
13190behave as if in the traditional C locale when performing
ac50fbac
CR
13191comparisons. That is, the current locale's collating sequence
13192is not taken into account, so
13193<B>b</B>
13194
13195will not collate between
13196<B>A</B>
13197
13198and
13199<B>B</B>,
13200
13201and upper-case and lower-case ASCII characters will collate together.
74091dd4
CR
13202<DT><B>globskipdots</B>
13203
13204<DD>
13205If set, pathname expansion will never match the filenames
13206<B>``.''</B>
13207
13208and
13209<B>``..''</B>,
13210
13211even if the pattern begins with a
13212<B>``.''</B>.
13213
13214This option is enabled by default.
17345e5a
JA
13215<DT><B>globstar</B>
13216
13217<DD>
0001803f 13218If set, the pattern <B>**</B> used in a pathname expansion context will
ac50fbac 13219match all files and zero or more directories and subdirectories.
17345e5a
JA
13220If the pattern is followed by a <B>/</B>, only directories and
13221subdirectories match.
13222<DT><B>gnu_errfmt</B>
13223
13224<DD>
13225If set, shell error messages are written in the standard GNU error
13226message format.
13227<DT><B>histappend</B>
13228
13229<DD>
13230If set, the history list is appended to the file named by the value
13231of the
0001803f 13232<FONT SIZE=-1><B>HISTFILE</B>
17345e5a 13233
0001803f 13234</FONT>
17345e5a
JA
13235variable when the shell exits, rather than overwriting the file.
13236<DT><B>histreedit</B>
13237
13238<DD>
13239If set, and
13240<B>readline</B>
13241
13242is being used, a user is given the opportunity to re-edit a
13243failed history substitution.
13244<DT><B>histverify</B>
13245
13246<DD>
a0c0a00f 13247If set, and
17345e5a
JA
13248<B>readline</B>
13249
13250is being used, the results of history substitution are not immediately
13251passed to the shell parser. Instead, the resulting line is loaded into
13252the <B>readline</B> editing buffer, allowing further modification.
13253<DT><B>hostcomplete</B>
13254
13255<DD>
13256If set, and
13257<B>readline</B>
13258
13259is being used, <B>bash</B> will attempt to perform hostname completion when a
13260word containing a <B>@</B> is being completed (see
13261<B>Completing</B>
13262
13263under
13264<FONT SIZE=-1><B>READLINE</B>
13265
13266</FONT>
74091dd4 13267
17345e5a
JA
13268above).
13269This is enabled by default.
13270<DT><B>huponexit</B>
13271
13272<DD>
13273If set, <B>bash</B> will send
13274<FONT SIZE=-1><B>SIGHUP</B>
13275
13276</FONT>
13277to all jobs when an interactive login shell exits.
a0c0a00f
CR
13278<DT><B>inherit_errexit</B>
13279
13280<DD>
13281If set, command substitution inherits the value of the <B>errexit</B> option,
13282instead of unsetting it in the subshell environment.
13283This option is enabled when <I>posix mode</I> is enabled.
17345e5a
JA
13284<DT><B>interactive_comments</B>
13285
13286<DD>
13287If set, allow a word beginning with
13288<B>#</B>
13289
13290to cause that word and all remaining characters on that
13291line to be ignored in an interactive shell (see
13292<FONT SIZE=-1><B>COMMENTS</B>
13293
13294</FONT>
74091dd4
CR
13295
13296above).
13297This option is enabled by default.
495aee44
CR
13298<DT><B>lastpipe</B>
13299
13300<DD>
13301If set, and job control is not active, the shell runs the last command of
13302a pipeline not executed in the background in the current shell environment.
17345e5a
JA
13303<DT><B>lithist</B>
13304
13305<DD>
13306If set, and the
13307<B>cmdhist</B>
13308
13309option is enabled, multi-line commands are saved to the history with
13310embedded newlines rather than using semicolon separators where possible.
d233b485
CR
13311<DT><B>localvar_inherit</B>
13312
13313<DD>
13314If set, local variables inherit the value and attributes of a variable of
13315the same name that exists at a previous scope before any new value is
13316assigned. The nameref attribute is not inherited.
13317<DT><B>localvar_unset</B>
13318
13319<DD>
13320If set, calling <B>unset</B> on local variables in previous function scopes
13321marks them so subsequent lookups find them unset until that function
13322returns. This is identical to the behavior of unsetting local variables
13323at the current function scope.
17345e5a
JA
13324<DT><B>login_shell</B>
13325
13326<DD>
13327The shell sets this option if it is started as a login shell (see
13328<FONT SIZE=-1><B>INVOCATION</B>
13329
13330</FONT>
74091dd4 13331
17345e5a
JA
13332above).
13333The value may not be changed.
13334<DT><B>mailwarn</B>
13335
13336<DD>
a0c0a00f 13337If set, and a file that <B>bash</B> is checking for mail has been
17345e5a
JA
13338accessed since the last time it was checked, the message ``The mail in
13339<I>mailfile</I> has been read'' is displayed.
13340<DT><B>no_empty_cmd_completion</B>
13341
13342<DD>
13343If set, and
13344<B>readline</B>
13345
13346is being used,
13347<B>bash</B>
13348
0001803f
CR
13349will not attempt to search the
13350<FONT SIZE=-1><B>PATH</B>
13351
13352</FONT>
13353for possible completions when
17345e5a
JA
13354completion is attempted on an empty line.
13355<DT><B>nocaseglob</B>
13356
13357<DD>
13358If set,
13359<B>bash</B>
13360
13361matches filenames in a case-insensitive fashion when performing pathname
13362expansion (see
13363<B>Pathname Expansion</B>
13364
74091dd4 13365
17345e5a
JA
13366above).
13367<DT><B>nocasematch</B>
13368
13369<DD>
13370If set,
13371<B>bash</B>
13372
13373matches patterns in a case-insensitive fashion when performing matching
a0c0a00f
CR
13374while executing <B>case</B> or <B>[[</B> conditional commands,
13375when performing pattern substitution word expansions,
13376or when filtering possible completions as part of programmable completion.
74091dd4
CR
13377<DT><B>noexpand_translation</B>
13378
13379<DD>
13380If set,
13381<B>bash</B>
13382
13383encloses the translated results of $&quot;...&quot; quoting in single quotes
13384instead of double quotes.
13385If the string is not translated, this has no effect.
17345e5a
JA
13386<DT><B>nullglob</B>
13387
13388<DD>
13389If set,
13390<B>bash</B>
13391
13392allows patterns which match no
13393files (see
13394<B>Pathname Expansion</B>
13395
74091dd4 13396
17345e5a
JA
13397above)
13398to expand to a null string, rather than themselves.
74091dd4
CR
13399<DT><B>patsub_replacement</B>
13400
13401<DD>
13402If set, <B>bash</B>
13403expands occurrences of <B>&amp;</B> in the replacement string of pattern
13404substitution to the text matched by the pattern, as described
13405under <B>Parameter Expansion</B>
13406
13407above.
13408This option is enabled by default.
17345e5a
JA
13409<DT><B>progcomp</B>
13410
13411<DD>
13412If set, the programmable completion facilities (see
74091dd4
CR
13413<B>Programmable Completion</B>
13414
13415above)
13416are enabled.
17345e5a 13417This option is enabled by default.
d233b485
CR
13418<DT><B>progcomp_alias</B>
13419
13420<DD>
13421If set, and programmable completion is enabled, <B>bash</B> treats a command
13422name that doesn't have any completions as a possible alias and attempts
13423alias expansion. If it has an alias, <B>bash</B> attempts programmable
13424completion using the command word resulting from the expanded alias.
17345e5a
JA
13425<DT><B>promptvars</B>
13426
13427<DD>
13428If set, prompt strings undergo
13429parameter expansion, command substitution, arithmetic
13430expansion, and quote removal after being expanded as described in
13431<FONT SIZE=-1><B>PROMPTING</B>
13432
13433</FONT>
74091dd4
CR
13434
13435above.
13436This option is enabled by default.
17345e5a
JA
13437<DT><B>restricted_shell</B>
13438
13439<DD>
74091dd4
CR
13440The shell sets this option if it is started in restricted mode
13441(see
17345e5a
JA
13442<FONT SIZE=-1><B>RESTRICTED SHELL</B>
13443
13444</FONT>
74091dd4 13445
17345e5a
JA
13446below).
13447The value may not be changed.
13448This is not reset when the startup files are executed, allowing
13449the startup files to discover whether or not a shell is restricted.
13450<DT><B>shift_verbose</B>
13451
13452<DD>
13453If set, the
13454<B>shift</B>
13455
13456builtin prints an error message when the shift count exceeds the
13457number of positional parameters.
13458<DT><B>sourcepath</B>
13459
13460<DD>
13461If set, the
74091dd4 13462<B>.</B> (<B>source</B>) builtin uses the value of
17345e5a
JA
13463<FONT SIZE=-1><B>PATH</B>
13464
13465</FONT>
13466to find the directory containing the file supplied as an argument.
13467This option is enabled by default.
74091dd4
CR
13468<DT><B>varredir_close</B>
13469
13470<DD>
13471If set, the shell automatically closes file descriptors assigned using the
13472<I>{varname}</I> redirection syntax (see
13473<FONT SIZE=-1><B>REDIRECTION</B>
13474
13475</FONT>
13476
13477above)
13478instead of leaving them open when the command completes.
17345e5a
JA
13479<DT><B>xpg_echo</B>
13480
13481<DD>
13482If set, the <B>echo</B> builtin expands backslash-escape sequences
13483by default.
13484</DL></DL>
13485
ac50fbac 13486
17345e5a
JA
13487<DT><B>suspend</B> [<B>-f</B>]<DD>
13488Suspend the execution of this shell until it receives a
13489<FONT SIZE=-1><B>SIGCONT</B>
13490
13491</FONT>
74091dd4
CR
13492signal. A login shell,
13493or a shell without job control enabled,
13494cannot be suspended; the
17345e5a
JA
13495<B>-f</B>
13496
13497option can be used to override this and force the suspension.
74091dd4
CR
13498The return status is 0 unless the shell is a login shell
13499or job control is not enabled
13500and
17345e5a
JA
13501<B>-f</B>
13502
74091dd4 13503is not supplied.
17345e5a
JA
13504<DT><B>test</B> <I>expr</I><DD>
13505
13506<DT><B>[</B> <I>expr</I> <B>]</B><DD>
ac50fbac 13507Return a status of 0 (true) or 1 (false) depending on
17345e5a
JA
13508the evaluation of the conditional expression
13509<I>expr</I>.
13510
13511Each operator and operand must be a separate argument.
74091dd4 13512Expressions are composed of the primaries described
8868edaf 13513
74091dd4
CR
13514above
13515under
17345e5a
JA
13516<FONT SIZE=-1><B>CONDITIONAL EXPRESSIONS</B>.
13517
13518</FONT>
13519<B>test</B> does not accept any options, nor does it accept and ignore
13520an argument of <B>--</B> as signifying the end of options.
13521<P>
13522
13523
13524Expressions may be combined using the following operators, listed
13525in decreasing order of precedence.
13526The evaluation depends on the number of arguments; see below.
495aee44 13527Operator precedence is used when there are five or more arguments.
17345e5a
JA
13528<DL COMPACT><DT><DD>
13529
13530<DL COMPACT>
13531<DT><B>! </B><I>expr</I>
13532
13533<DD>
13534True if
13535<I>expr</I>
13536
13537is false.
13538<DT><B>( </B><I>expr</I> )
13539
13540<DD>
13541Returns the value of <I>expr</I>.
13542This may be used to override the normal precedence of operators.
13543<DT><I>expr1</I> -<B>a</B> <I>expr2</I><DD>
13544True if both
13545<I>expr1</I>
13546
13547and
13548<I>expr2</I>
13549
13550are true.
13551<DT><I>expr1</I> -<B>o</B> <I>expr2</I><DD>
13552True if either
13553<I>expr1</I>
13554
13555or
13556<I>expr2</I>
13557
13558is true.
13559
13560</DL>
13561<P>
13562
13563<B>test</B> and <B>[</B> evaluate conditional
13564expressions using a set of rules based on the number of arguments.
13565<P>
13566
13567
13568
13569<DL COMPACT>
13570<DT>0 arguments<DD>
13571The expression is false.
13572<DT>1 argument<DD>
13573The expression is true if and only if the argument is not null.
13574<DT>2 arguments<DD>
13575If the first argument is <B>!</B>, the expression is true if and
13576only if the second argument is null.
74091dd4
CR
13577If the first argument is one of the unary conditional operators listed
13578
13579above
17345e5a
JA
13580under
13581<FONT SIZE=-1><B>CONDITIONAL EXPRESSIONS</B>,
13582
13583</FONT>
13584the expression is true if the unary test is true.
13585If the first argument is not a valid unary conditional operator, the expression
13586is false.
13587<DT>3 arguments<DD>
495aee44 13588The following conditions are applied in the order listed.
74091dd4
CR
13589If the second argument is one of the binary conditional operators listed
13590
13591above
17345e5a
JA
13592under
13593<FONT SIZE=-1><B>CONDITIONAL EXPRESSIONS</B>,
13594
13595</FONT>
13596the result of the expression is the result of the binary test using
13597the first and third arguments as operands.
13598The <B>-a</B> and <B>-o</B> operators are considered binary operators
a0c0a00f 13599when there are three arguments.
17345e5a
JA
13600If the first argument is <B>!</B>, the value is the negation of
13601the two-argument test using the second and third arguments.
13602If the first argument is exactly <B>(</B> and the third argument is
13603exactly <B>)</B>, the result is the one-argument test of the second
13604argument.
13605Otherwise, the expression is false.
13606<DT>4 arguments<DD>
74091dd4 13607The following conditions are applied in the order listed.
17345e5a
JA
13608If the first argument is <B>!</B>, the result is the negation of
13609the three-argument expression composed of the remaining arguments.
74091dd4
CR
13610the two-argument test using the second and third arguments.
13611If the first argument is exactly <B>(</B> and the fourth argument is
13612exactly <B>)</B>, the result is the two-argument test of the second
13613and third arguments.
a0c0a00f 13614Otherwise, the expression is parsed and evaluated according to
17345e5a
JA
13615precedence using the rules listed above.
13616<DT>5 or more arguments<DD>
13617The expression is parsed and evaluated according to precedence
13618using the rules listed above.
495aee44
CR
13619<P>
13620
13621
13622</DL>
13623<P>
13624
13625When used with <B>test</B> or <B>[</B>, the <B>&lt;</B> and <B>&gt;</B> operators
13626sort lexicographically using ASCII ordering.
13627</DL>
17345e5a
JA
13628
13629
13630<DT><B>times</B>
13631
13632<DD>
13633Print the accumulated user and system times for the shell and
13634for processes run from the shell. The return status is 0.
13635<DT><B>trap</B> [<B>-lp</B>] [[<I>arg</I>] <I>sigspec</I> ...]<DD>
13636The command
13637<I>arg</I>
13638
13639is to be read and executed when the shell receives
13640signal(s)
13641<I>sigspec</I>.
13642
13643If
13644<I>arg</I>
13645
13646is absent (and there is a single <I>sigspec</I>) or
13647<B>-</B>,
13648
13649each specified signal is
13650reset to its original disposition (the value it had
13651upon entrance to the shell).
a0c0a00f 13652If
17345e5a
JA
13653<I>arg</I>
13654
13655is the null string the signal specified by each
13656<I>sigspec</I>
13657
13658is ignored by the shell and by the commands it invokes.
13659If
13660<I>arg</I>
13661
13662is not present and
13663<B>-p</B>
13664
13665has been supplied, then the trap commands associated with each
13666<I>sigspec</I>
13667
13668are displayed.
13669If no arguments are supplied or if only
13670<B>-p</B>
13671
13672is given,
13673<B>trap</B>
13674
13675prints the list of commands associated with each signal.
13676The
13677<B>-l</B>
13678
13679option causes the shell to print a list of signal names and
13680their corresponding numbers.
13681Each
13682<I>sigspec</I>
13683
13684is either
13685a signal name defined in &lt;<I>signal.h</I>&gt;, or a signal number.
495aee44
CR
13686Signal names are case insensitive and the
13687<FONT SIZE=-1><B>SIG</B>
13688
13689</FONT>
13690prefix is optional.
0001803f
CR
13691<P>
13692
13693
17345e5a
JA
13694If a
13695<I>sigspec</I>
13696
13697is
13698<FONT SIZE=-1><B>EXIT</B>
13699
13700</FONT>
13701(0) the command
13702<I>arg</I>
13703
13704is executed on exit from the shell.
13705If a
13706<I>sigspec</I>
13707
13708is
13709<FONT SIZE=-1><B>DEBUG</B>,
13710
13711</FONT>
13712the command
13713<I>arg</I>
13714
13715is executed before every <I>simple command</I>, <I>for</I> command,
13716<I>case</I> command, <I>select</I> command, every arithmetic <I>for</I>
13717command, and before the first command executes in a shell function (see
13718<FONT SIZE=-1><B>SHELL GRAMMAR</B>
13719
13720</FONT>
74091dd4 13721
17345e5a
JA
13722above).
13723Refer to the description of the <B>extdebug</B> option to the
13724<B>shopt</B> builtin for details of its effect on the <B>DEBUG</B> trap.
13725If a
13726<I>sigspec</I>
13727
0001803f
CR
13728is
13729<FONT SIZE=-1><B>RETURN</B>,
13730
13731</FONT>
13732the command
13733<I>arg</I>
13734
495aee44
CR
13735is executed each time a shell function or a script executed with
13736the <B>.</B> or <B>source</B> builtins finishes executing.
0001803f
CR
13737<P>
13738
13739
13740If a
13741<I>sigspec</I>
13742
17345e5a
JA
13743is
13744<FONT SIZE=-1><B>ERR</B>,
13745
13746</FONT>
13747the command
13748<I>arg</I>
13749
a0c0a00f 13750is executed whenever
ac50fbac 13751a pipeline (which may consist of a single simple
a0c0a00f 13752command), a list, or a compound command returns a
ac50fbac 13753non-zero exit status,
17345e5a
JA
13754subject to the following conditions.
13755The
13756<FONT SIZE=-1><B>ERR</B>
13757
13758</FONT>
13759trap is not executed if the failed
13760command is part of the command list immediately following a
13761<B>while</B>
13762
13763or
13764<B>until</B>
13765
a0c0a00f 13766keyword,
17345e5a
JA
13767part of the test in an
13768<I>if</I>
13769
13770statement, part of a command executed in a
13771<B>&amp;&amp;</B>
13772
13773or
13774<B>||</B>
13775
ac50fbac
CR
13776list except the command following the final <B>&amp;&amp;</B> or <B>||</B>,
13777any command in a pipeline but the last,
13778or if the command's return value is
13779being inverted using
17345e5a
JA
13780<B>!</B>.
13781
ac50fbac 13782These are the same conditions obeyed by the <B>errexit</B> (<B>-e</B>) option.
0001803f 13783<P>
17345e5a 13784
17345e5a 13785
17345e5a
JA
13786Signals ignored upon entry to the shell cannot be trapped or reset.
13787Trapped signals that are not being ignored are reset to their original
0001803f 13788values in a subshell or subshell environment when one is created.
17345e5a
JA
13789The return status is false if any
13790<I>sigspec</I>
13791
13792is invalid; otherwise
13793<B>trap</B>
13794
13795returns true.
13796<DT><B>type</B> [<B>-aftpP</B>] <I>name</I> [<I>name</I> ...]<DD>
a0c0a00f 13797With no options,
17345e5a
JA
13798indicate how each
13799<I>name</I>
13800
13801would be interpreted if used as a command name.
13802If the
13803<B>-t</B>
13804
13805option is used,
13806<B>type</B>
13807
13808prints a string which is one of
13809<I>alias</I>,
13810
13811<I>keyword</I>,
13812
13813<I>function</I>,
13814
13815<I>builtin</I>,
13816
13817or
a0c0a00f 13818<I>file</I>
17345e5a
JA
13819
13820if
13821<I>name</I>
13822
13823is an alias, shell reserved word, function, builtin, or disk file,
13824respectively.
13825If the
13826<I>name</I>
13827
13828is not found, then nothing is printed, and an exit status of false
13829is returned.
13830If the
13831<B>-p</B>
13832
13833option is used,
13834<B>type</B>
13835
13836either returns the name of the disk file
13837that would be executed if
13838<I>name</I>
13839
13840were specified as a command name,
13841or nothing if
13842<TT>type -t name</TT>
13843
13844would not return
13845<I>file</I>.
13846
13847The
13848<B>-P</B>
13849
13850option forces a
13851<FONT SIZE=-1><B>PATH</B>
13852
13853</FONT>
13854search for each <I>name</I>, even if
13855<TT>type -t name</TT>
13856
13857would not return
13858<I>file</I>.
13859
13860If a command is hashed,
13861<B>-p</B>
13862
13863and
13864<B>-P</B>
13865
ac50fbac 13866print the hashed value, which is not necessarily the file that appears
a0c0a00f 13867first in
17345e5a
JA
13868<FONT SIZE=-1><B>PATH</B>.
13869
13870</FONT>
13871If the
13872<B>-a</B>
13873
a0c0a00f 13874option is used,
17345e5a
JA
13875<B>type</B>
13876
13877prints all of the places that contain
a0c0a00f 13878an executable named
17345e5a
JA
13879<I>name</I>.
13880
13881This includes aliases and functions,
a0c0a00f 13882if and only if the
17345e5a
JA
13883<B>-p</B>
13884
13885option is not also used.
13886The table of hashed commands is not consulted
13887when using
13888<B>-a</B>.
13889
13890The
13891<B>-f</B>
13892
13893option suppresses shell function lookup, as with the <B>command</B> builtin.
13894<B>type</B>
13895
13896returns true if all of the arguments are found, false if
13897any are not found.
8868edaf
CR
13898<DT><B>ulimit</B> [<B>-HS</B>] <B>-a</B><DD>
13899
13900<DT><B>ulimit</B> [<B>-HS</B>] [<B>-bcdefiklmnpqrstuvxPRT</B> [<I>limit</I>]]<DD>
13901
17345e5a
JA
13902Provides control over the resources available to the shell and to
13903processes started by it, on systems that allow such control.
13904The <B>-H</B> and <B>-S</B> options specify that the hard or soft limit is
13905set for the given resource.
13906A hard limit cannot be increased by a non-root user once it is set;
13907a soft limit may be increased up to the value of the hard limit.
13908If neither <B>-H</B> nor <B>-S</B> is specified, both the soft and hard
13909limits are set.
13910The value of
13911<I>limit</I>
13912
13913can be a number in the unit specified for the resource
13914or one of the special values
13915<B>hard</B>,
13916
13917<B>soft</B>,
13918
13919or
13920<B>unlimited</B>,
13921
13922which stand for the current hard limit, the current soft limit, and
13923no limit, respectively.
13924If
13925<I>limit</I>
13926
13927is omitted, the current value of the soft limit of the resource is
13928printed, unless the <B>-H</B> option is given. When more than one
8868edaf
CR
13929resource is specified, the limit name and unit, if appropriate,
13930are printed before the value.
17345e5a
JA
13931Other options are interpreted as follows:
13932<DL COMPACT><DT><DD>
13933
13934<DL COMPACT>
13935<DT><B>-a</B>
13936
13937<DD>
8868edaf 13938All current limits are reported; no limits are set
17345e5a
JA
13939<DT><B>-b</B>
13940
13941<DD>
13942The maximum socket buffer size
13943<DT><B>-c</B>
13944
13945<DD>
13946The maximum size of core files created
13947<DT><B>-d</B>
13948
13949<DD>
13950The maximum size of a process's data segment
13951<DT><B>-e</B>
13952
13953<DD>
13954The maximum scheduling priority (&quot;nice&quot;)
13955<DT><B>-f</B>
13956
13957<DD>
13958The maximum size of files written by the shell and its children
13959<DT><B>-i</B>
13960
13961<DD>
13962The maximum number of pending signals
a0c0a00f
CR
13963<DT><B>-k</B>
13964
13965<DD>
13966The maximum number of kqueues that may be allocated
17345e5a
JA
13967<DT><B>-l</B>
13968
13969<DD>
13970The maximum size that may be locked into memory
13971<DT><B>-m</B>
13972
13973<DD>
0001803f 13974The maximum resident set size (many systems do not honor this limit)
17345e5a
JA
13975<DT><B>-n</B>
13976
13977<DD>
13978The maximum number of open file descriptors (most systems do not
13979allow this value to be set)
13980<DT><B>-p</B>
13981
13982<DD>
13983The pipe size in 512-byte blocks (this may not be set)
13984<DT><B>-q</B>
13985
13986<DD>
13987The maximum number of bytes in POSIX message queues
13988<DT><B>-r</B>
13989
13990<DD>
13991The maximum real-time scheduling priority
13992<DT><B>-s</B>
13993
13994<DD>
13995The maximum stack size
13996<DT><B>-t</B>
13997
13998<DD>
13999The maximum amount of cpu time in seconds
14000<DT><B>-u</B>
14001
14002<DD>
14003The maximum number of processes available to a single user
14004<DT><B>-v</B>
14005
14006<DD>
495aee44
CR
14007The maximum amount of virtual memory available to the shell and, on
14008some systems, to its children
17345e5a
JA
14009<DT><B>-x</B>
14010
14011<DD>
14012The maximum number of file locks
a0c0a00f
CR
14013<DT><B>-P</B>
14014
14015<DD>
14016The maximum number of pseudoterminals
8868edaf
CR
14017<DT><B>-R</B>
14018
14019<DD>
14020The maximum time a real-time process can run before blocking, in microseconds
17345e5a
JA
14021<DT><B>-T</B>
14022
14023<DD>
14024The maximum number of threads
14025
14026</DL>
14027<P>
14028
14029If
14030<I>limit</I>
14031
ac50fbac 14032is given, and the
17345e5a
JA
14033<B>-a</B>
14034
ac50fbac
CR
14035option is not used,
14036<I>limit</I> is the new value of the specified resource.
17345e5a
JA
14037If no option is given, then
14038<B>-f</B>
14039
14040is assumed. Values are in 1024-byte increments, except for
14041<B>-t</B>,
14042
ac50fbac 14043which is in seconds;
8868edaf
CR
14044<B>-R</B>,
14045
14046which is in microseconds;
17345e5a
JA
14047<B>-p</B>,
14048
ac50fbac 14049which is in units of 512-byte blocks;
a0c0a00f
CR
14050<B>-P</B>,
14051
17345e5a
JA
14052<B>-T</B>,
14053
14054<B>-b</B>,
14055
a0c0a00f
CR
14056<B>-k</B>,
14057
17345e5a
JA
14058<B>-n</B>,
14059
14060and
14061<B>-u</B>,
14062
a0c0a00f 14063which are unscaled values;
d233b485 14064and, when in posix mode,
a0c0a00f
CR
14065<B>-c</B>
14066
14067and
14068<B>-f</B>,
14069
14070which are in 512-byte increments.
17345e5a
JA
14071The return status is 0 unless an invalid option or argument is supplied,
14072or an error occurs while setting a new limit.
14073</DL>
14074
14075<DT><B>umask</B> [<B>-p</B>] [<B>-S</B>] [<I>mode</I>]<DD>
a0c0a00f 14076The user file-creation mask is set to
17345e5a
JA
14077<I>mode</I>.
14078
14079If
14080<I>mode</I>
14081
14082begins with a digit, it
14083is interpreted as an octal number; otherwise
14084it is interpreted as a symbolic mode mask similar
14085to that accepted by
14086<I>chmod</I>(1).
14087
14088If
14089<I>mode</I>
14090
14091is omitted, the current value of the mask is printed.
14092The
14093<B>-S</B>
14094
14095option causes the mask to be printed in symbolic form; the
14096default output is an octal number.
14097If the
14098<B>-p</B>
14099
14100option is supplied, and
14101<I>mode</I>
14102
14103is omitted, the output is in a form that may be reused as input.
14104The return status is 0 if the mode was successfully changed or if
14105no <I>mode</I> argument was supplied, and false otherwise.
14106<DT><B>unalias</B> [-<B>a</B>] [<I>name</I> ...]<DD>
14107Remove each <I>name</I> from the list of defined aliases. If
14108<B>-a</B>
14109
14110is supplied, all alias definitions are removed. The return
14111value is true unless a supplied
14112<I>name</I>
14113
14114is not a defined alias.
ac50fbac 14115<DT><B>unset</B> [-<B>fv</B>] [-<B>n</B>] [<I>name</I> ...]<DD>
17345e5a
JA
14116For each
14117<I>name</I>,
14118
14119remove the corresponding variable or function.
ac50fbac 14120If the
17345e5a
JA
14121<B>-v</B>
14122
14123option is given, each
14124<I>name</I>
14125
ac50fbac 14126refers to a shell variable, and that variable is removed.
17345e5a
JA
14127Read-only variables may not be unset.
14128If
14129<B>-f</B>
14130
14131is specified, each
14132<I>name</I>
14133
14134refers to a shell function, and the function definition
14135is removed.
ac50fbac
CR
14136If the
14137<B>-n</B>
14138
14139option is supplied, and <I>name</I> is a variable with the <I>nameref</I>
14140attribute, <I>name</I> will be unset rather than the variable it
14141references.
14142<B>-n</B> has no effect if the <B>-f</B> option is supplied.
14143If no options are supplied, each <I>name</I> refers to a variable; if
8868edaf 14144there is no variable by that name, a function with that name, if any, is
ac50fbac 14145unset.
17345e5a
JA
14146Each unset variable or function is removed from the environment
14147passed to subsequent commands.
14148If any of
8868edaf 14149<FONT SIZE=-1><B>BASH_ALIASES</B>,
0001803f
CR
14150
14151</FONT>
8868edaf 14152<FONT SIZE=-1><B>BASH_ARGV0</B>,
17345e5a
JA
14153
14154</FONT>
8868edaf 14155<FONT SIZE=-1><B>BASH_CMDS</B>,
17345e5a
JA
14156
14157</FONT>
8868edaf 14158<FONT SIZE=-1><B>BASH_COMMAND</B>,
17345e5a
JA
14159
14160</FONT>
8868edaf
CR
14161<FONT SIZE=-1><B>BASH_SUBSHELL</B>,
14162
14163</FONT>
14164<FONT SIZE=-1><B>BASHPID</B>,
14165
14166</FONT>
14167<FONT SIZE=-1><B>COMP_WORDBREAKS</B>,
14168
14169</FONT>
14170<FONT SIZE=-1><B>DIRSTACK</B>,
14171
14172</FONT>
14173<FONT SIZE=-1><B>EPOCHREALTIME</B>,
14174
14175</FONT>
14176<FONT SIZE=-1><B>EPOCHSECONDS</B>,
17345e5a
JA
14177
14178</FONT>
14179<FONT SIZE=-1><B>FUNCNAME</B>,
14180
14181</FONT>
14182<FONT SIZE=-1><B>GROUPS</B>,
14183
8868edaf
CR
14184</FONT>
14185<FONT SIZE=-1><B>HISTCMD</B>,
14186
14187</FONT>
14188<FONT SIZE=-1><B>LINENO</B>,
14189
14190</FONT>
14191<FONT SIZE=-1><B>RANDOM</B>,
14192
14193</FONT>
14194<FONT SIZE=-1><B>SECONDS</B>,
14195
17345e5a
JA
14196</FONT>
14197or
8868edaf 14198<FONT SIZE=-1><B>SRANDOM</B>
17345e5a
JA
14199
14200</FONT>
14201are unset, they lose their special properties, even if they are
14202subsequently reset. The exit status is true unless a
14203<I>name</I>
14204
74091dd4 14205is readonly or may not be unset.
8868edaf 14206<DT><B>wait</B> [<B>-fn</B>] [-p <I>varname</I>] [<I>id ...</I>]<DD>
ac50fbac 14207Wait for each specified child process and return its termination status.
17345e5a 14208Each
d233b485 14209<I>id</I>
17345e5a
JA
14210
14211may be a process
14212ID or a job specification; if a job spec is given, all processes
14213in that job's pipeline are waited for. If
d233b485 14214<I>id</I>
17345e5a 14215
8868edaf
CR
14216is not given,
14217<B>wait</B> waits for all running background jobs and
14218the last-executed process substitution, if its process id is the same as
14219<B>$!</B>,
14220and the return status is zero.
14221If the <B>-n</B> option is supplied,
14222<B>wait</B> waits for a single job
14223from the list of <I>id</I>s or, if no <I>id</I>s are supplied, any job,
14224to complete and returns its exit status.
14225If none of the supplied arguments is a child of the shell, or if no arguments
14226are supplied and the shell has no unwaited-for children, the exit status
14227is 127.
14228If the <B>-p</B> option is supplied, the process or job identifier of the job
14229for which the exit status is returned is assigned to the variable
14230<I>varname</I> named by the option argument.
14231The variable will be unset initially, before any assignment.
14232This is useful only when the <B>-n</B> option is supplied.
14233Supplying the <B>-f</B> option, when job control is enabled,
14234forces <B>wait</B> to wait for <I>id</I> to terminate before returning
14235its status, instead of returning when it changes status.
ac50fbac 14236If
d233b485 14237<I>id</I>
17345e5a 14238
74091dd4
CR
14239specifies a non-existent process or job, the return status is 127.
14240If <B>wait</B> is interrupted by a signal, the return status will be greater
14241than 128, as described under
14242<B>SIGNALS</B>
14243
14244
14245above.
14246Otherwise, the return status is the exit status of the last
17345e5a 14247process or job waited for.
8868edaf
CR
14248</DL>
14249<A NAME="lbDC">&nbsp;</A>
14250<H3>SHELL COMPATIBILITY MODE</H3>
14251
74091dd4
CR
14252Bash-4.0 introduced the concept of a <I>shell compatibility level</I>,
14253specified as a set of options to the shopt builtin (
8868edaf
CR
14254<B>compat31</B>,
14255
14256<B>compat32</B>,
14257
14258<B>compat40</B>,
14259
14260<B>compat41</B>,
14261
14262and so on).
14263There is only one current
14264compatibility level -- each option is mutually exclusive.
14265The compatibility level is intended to allow users to select behavior
14266from previous versions that is incompatible with newer versions
14267while they migrate scripts to use current features and
14268behavior. It's intended to be a temporary solution.
14269<P>
14270
14271This section does not mention behavior that is standard for a particular
14272version (e.g., setting <B>compat32</B> means that quoting the rhs of the regexp
14273matching operator quotes special regexp characters in the word, which is
74091dd4 14274default behavior in bash-3.2 and subsequent versions).
8868edaf
CR
14275<P>
14276
14277If a user enables, say, <B>compat32</B>, it may affect the behavior of other
14278compatibility levels up to and including the current compatibility level.
14279The idea is that each compatibility level controls behavior that changed
14280in that version of <B>bash</B>,
14281but that behavior may have been present in earlier versions.
14282For instance, the change to use locale-based comparisons with the <B>[[</B>
14283command came in bash-4.1, and earlier versions used ASCII-based comparisons,
14284so enabling <B>compat32</B> will enable ASCII-based comparisons as well.
14285That granularity may not be sufficient for
14286all uses, and as a result users should employ compatibility levels carefully.
14287Read the documentation for a particular feature to find out the
14288current behavior.
14289<P>
14290
14291Bash-4.3 introduced a new shell variable:
14292<FONT SIZE=-1><B>BASH_COMPAT</B>.
14293
14294</FONT>
14295The value assigned
14296to this variable (a decimal version number like 4.2, or an integer
14297corresponding to the <B>compat</B><I>NN</I> option, like 42) determines the
14298compatibility level.
14299<P>
14300
14301Starting with bash-4.4, Bash has begun deprecating older compatibility
14302levels.
14303Eventually, the options will be removed in favor of
14304<FONT SIZE=-1><B>BASH_COMPAT</B>.
14305
14306</FONT>
14307<P>
14308
14309Bash-5.0 is the final version for which there will be an individual shopt
14310option for the previous version. Users should use
14311<FONT SIZE=-1><B>BASH_COMPAT</B>
14312
14313</FONT>
14314on bash-5.0 and later versions.
14315<P>
14316
14317The following table describes the behavior changes controlled by each
14318compatibility level setting.
14319The <B>compat</B><I>NN</I> tag is used as shorthand for setting the
14320compatibility level
14321to <I>NN</I> using one of the following mechanisms.
14322For versions prior to bash-5.0, the compatibility level may be set using
14323the corresponding <B>compat</B><I>NN</I> shopt option.
14324For bash-4.3 and later versions, the
14325<FONT SIZE=-1><B>BASH_COMPAT</B>
14326
14327</FONT>
14328variable is preferred,
14329and it is required for bash-5.1 and later versions.
14330<DL COMPACT>
14331<DT><B>compat31</B><DD>
14332
14333<DL COMPACT><DT><DD>
14334<DL COMPACT>
14335<DT>*<DD>
14336quoting the rhs of the <B>[[</B> command's regexp matching operator (=~)
14337has no special effect
14338</DL></DL>
14339
14340
14341<DT><B>compat32</B><DD>
14342
14343<DL COMPACT><DT><DD>
14344<DL COMPACT>
14345<DT>*<DD>
14346interrupting a command list such as &quot;a ; b ; c&quot; causes the execution
14347of the next command in the list (in bash-4.0 and later versions,
14348the shell acts as if it received the interrupt, so
14349interrupting one command in a list aborts the execution of the
14350entire list)
14351</DL></DL>
14352
14353
14354<DT><B>compat40</B><DD>
14355
14356<DL COMPACT><DT><DD>
14357<DL COMPACT>
14358<DT>*<DD>
14359the <B>&lt;</B> and <B>&gt;</B> operators to the <B>[[</B> command do not
14360consider the current locale when comparing strings; they use ASCII
14361ordering.
14362Bash versions prior to bash-4.1 use ASCII collation and
14363<I>strcmp</I>(3);
14364
14365bash-4.1 and later use the current locale's collation sequence and
14366<I>strcoll</I>(3).
14367
14368</DL></DL>
14369
14370
14371<DT><B>compat41</B><DD>
14372
14373<DL COMPACT><DT><DD>
14374<DL COMPACT>
14375<DT>*<DD>
14376in <I>posix</I> mode, <B>time</B> may be followed by options and still be
14377recognized as a reserved word (this is POSIX interpretation 267)
14378<DT>*<DD>
14379in <I>posix</I> mode, the parser requires that an even number of single
14380quotes occur in the <I>word</I> portion of a double-quoted
14381parameter expansion and treats them specially, so that characters within
14382the single quotes are considered quoted
14383(this is POSIX interpretation 221)
14384</DL></DL>
14385
14386
14387<DT><B>compat42</B><DD>
14388
14389<DL COMPACT><DT><DD>
14390<DL COMPACT>
14391<DT>*<DD>
14392the replacement string in double-quoted pattern substitution does not
14393undergo quote removal, as it does in versions after bash-4.2
14394<DT>*<DD>
14395in posix mode, single quotes are considered special when expanding
14396the <I>word</I> portion of a double-quoted parameter expansion
14397and can be used to quote a closing brace or other special character
14398(this is part of POSIX interpretation 221);
14399in later versions, single quotes
14400are not special within double-quoted word expansions
14401</DL></DL>
14402
14403
14404<DT><B>compat43</B><DD>
14405
14406<DL COMPACT><DT><DD>
14407<DL COMPACT>
14408<DT>*<DD>
14409the shell does not print a warning message if an attempt is made to
14410use a quoted compound assignment as an argument to declare
74091dd4 14411(e.g., declare -a foo=aq(1 2)aq). Later versions warn that this usage is
8868edaf
CR
14412deprecated
14413<DT>*<DD>
14414word expansion errors are considered non-fatal errors that cause the
14415current command to fail, even in posix mode
14416(the default behavior is to make them fatal errors that cause the shell
14417to exit)
14418<DT>*<DD>
14419when executing a shell function, the loop state (while/until/etc.)
14420is not reset, so <B>break</B> or <B>continue</B> in that function will break
14421or continue loops in the calling context. Bash-4.4 and later reset
14422the loop state to prevent this
14423</DL></DL>
14424
14425
14426<DT><B>compat44</B><DD>
14427
14428<DL COMPACT><DT><DD>
14429<DL COMPACT>
14430<DT>*<DD>
14431the shell sets up the values used by
14432<FONT SIZE=-1><B>BASH_ARGV</B>
14433
14434</FONT>
14435and
14436<FONT SIZE=-1><B>BASH_ARGC</B>
14437
14438</FONT>
14439so they can expand to the shell's positional parameters even if extended
14440debugging mode is not enabled
14441<DT>*<DD>
14442a subshell inherits loops from its parent context, so <B>break</B>
14443or <B>continue</B> will cause the subshell to exit.
14444Bash-5.0 and later reset the loop state to prevent the exit
14445<DT>*<DD>
14446variable assignments preceding builtins like <B>export</B> and <B>readonly</B>
14447that set attributes continue to affect variables with the same
14448name in the calling environment even if the shell is not in posix
14449mode
14450</DL></DL>
14451
14452
14453<DT><B>compat50</B><DD>
14454
14455<DL COMPACT><DT><DD>
14456<DL COMPACT>
14457<DT>*<DD>
14458Bash-5.1 changed the way
14459<FONT SIZE=-1><B>$RANDOM</B>
14460
14461</FONT>
14462is generated to introduce slightly
14463more randomness. If the shell compatibility level is set to 50 or
14464lower, it reverts to the method from bash-5.0 and previous versions,
14465so seeding the random number generator by assigning a value to
14466<FONT SIZE=-1><B>RANDOM</B>
14467
14468</FONT>
14469will produce the same sequence as in bash-5.0
14470<DT>*<DD>
14471If the command hash table is empty, bash versions prior to bash-5.1
14472printed an informational message to that effect, even when producing
14473output that can be reused as input. Bash-5.1 suppresses that message
14474when the <B>-l</B> option is supplied.
14475</DL></DL>
14476
14477
74091dd4
CR
14478<DT><B>compat51</B><DD>
14479
14480<DL COMPACT><DT><DD>
14481<DL COMPACT>
14482<DT>*<DD>
14483The <B>unset</B> builtin treats attempts to unset array subscripts <B>@</B>
14484and <B>*</B> differently depending on whether the array is indexed or
14485associative, and differently than in previous versions.
14486</DL></DL>
14487
14488
17345e5a
JA
14489
14490
14491</DL>
8868edaf 14492<A NAME="lbDD">&nbsp;</A>
17345e5a
JA
14493<H3>RESTRICTED SHELL</H3>
14494
14495
14496
14497<P>
14498
14499If
14500<B>bash</B>
14501
14502is started with the name
14503<B>rbash</B>,
14504
14505or the
14506<B>-r</B>
14507
14508option is supplied at invocation,
14509the shell becomes restricted.
14510A restricted shell is used to
14511set up an environment more controlled than the standard shell.
14512It behaves identically to
14513<B>bash</B>
14514
14515with the exception that the following are disallowed or not performed:
14516<DL COMPACT>
14517<DT>*<DD>
14518changing directories with <B>cd</B>
14519<DT>*<DD>
14520setting or unsetting the values of
0001803f 14521<FONT SIZE=-1><B>SHELL</B>,
17345e5a 14522
0001803f
CR
14523</FONT>
14524<FONT SIZE=-1><B>PATH</B>,
17345e5a 14525
8868edaf
CR
14526</FONT>
14527<FONT SIZE=-1><B>HISTFILE</B>,
14528
0001803f
CR
14529</FONT>
14530<FONT SIZE=-1><B>ENV</B>,
17345e5a 14531
0001803f 14532</FONT>
17345e5a 14533or
0001803f 14534<FONT SIZE=-1><B>BASH_ENV</B>
17345e5a 14535
0001803f 14536</FONT>
17345e5a
JA
14537<DT>*<DD>
14538specifying command names containing
14539<B>/</B>
14540
14541<DT>*<DD>
ac50fbac 14542specifying a filename containing a
17345e5a
JA
14543<B>/</B>
14544
14545as an argument to the
14546<B>.</B>
14547
8868edaf
CR
14548builtin command
14549<DT>*<DD>
14550specifying a filename containing a slash as an argument to the
14551<B>history</B>
14552
17345e5a
JA
14553builtin command
14554<DT>*<DD>
495aee44 14555specifying a filename containing a slash as an argument to the
17345e5a
JA
14556<B>-p</B>
14557
14558option to the
14559<B>hash</B>
14560
14561builtin command
14562<DT>*<DD>
14563importing function definitions from the shell environment at startup
14564<DT>*<DD>
0001803f
CR
14565parsing the value of
14566<FONT SIZE=-1><B>SHELLOPTS</B>
14567
14568</FONT>
14569from the shell environment at startup
17345e5a
JA
14570<DT>*<DD>
14571redirecting output using the &gt;, &gt;|, &lt;&gt;, &gt;&amp;, &amp;&gt;, and &gt;&gt; redirection operators
14572<DT>*<DD>
14573using the
14574<B>exec</B>
14575
14576builtin command to replace the shell with another command
14577<DT>*<DD>
14578adding or deleting builtin commands with the
14579<B>-f</B>
14580
14581and
14582<B>-d</B>
14583
14584options to the
14585<B>enable</B>
14586
14587builtin command
14588<DT>*<DD>
495aee44 14589using the <B>enable</B> builtin command to enable disabled shell builtins
17345e5a
JA
14590<DT>*<DD>
14591specifying the
14592<B>-p</B>
14593
14594option to the
14595<B>command</B>
14596
14597builtin command
14598<DT>*<DD>
14599turning off restricted mode with
74091dd4 14600<B>set +r</B> or <B>shopt -u restricted_shell</B>.
17345e5a
JA
14601</DL>
14602<P>
14603
14604These restrictions are enforced after any startup files are read.
14605<P>
14606
14607
14608 When a command that is found to be a shell script is executed
14609(see
14610<FONT SIZE=-1><B>COMMAND EXECUTION</B>
14611
14612</FONT>
14613
14614above),
14615
14616<B>rbash</B>
14617
14618turns off any restrictions in the shell spawned to execute the
14619script.
14620
14621
8868edaf 14622<A NAME="lbDE">&nbsp;</A>
17345e5a
JA
14623<H3>SEE ALSO</H3>
14624
14625
14626<DL COMPACT>
14627<DT><I>Bash Reference Manual</I>, Brian Fox and Chet Ramey<DD>
14628<DT><I>The Gnu Readline Library</I>, Brian Fox and Chet Ramey<DD>
14629<DT><I>The Gnu History Library</I>, Brian Fox and Chet Ramey<DD>
ac50fbac
CR
14630<DT><I>Portable Operating System Interface (POSIX) Part 2: Shell and Utilities</I>, IEEE --<DD>
14631<A HREF="http://pubs.opengroup.org/onlinepubs/9699919799/">http://pubs.opengroup.org/onlinepubs/9699919799/</A>
14632<DT><A HREF="http://tiswww.case.edu/~chet/bash/POSIX">http://tiswww.case.edu/~chet/bash/POSIX</A> -- a description of posix mode<DD>
17345e5a
JA
14633<DT><I>sh</I>(1), <I>ksh</I>(1), <I>csh</I>(1)<DD>
14634<DT><I>emacs</I>(1), <I>vi</I>(1)<DD>
14635<DT><I>readline</I>(3)<DD>
14636
14637</DL>
8868edaf 14638<A NAME="lbDF">&nbsp;</A>
17345e5a
JA
14639<H3>FILES</H3>
14640
14641
14642<DL COMPACT>
14643<DT>
14644<A HREF="file:/bin/bash"><I>/bin/bash</I></A>
14645
14646<DD>
14647The <B>bash</B> executable
14648<DT>
14649<A HREF="file:/etc/profile"><I>/etc/profile</I></A>
14650
14651<DD>
14652The systemwide initialization file, executed for login shells
14653<DT>
14654<A HREF="file:~/.bash_profile"><I>~/.bash_profile</I></A>
14655
14656<DD>
14657The personal initialization file, executed for login shells
14658<DT>
14659<A HREF="file:~/.bashrc"><I>~/.bashrc</I></A>
14660
14661<DD>
14662The individual per-interactive-shell startup file
14663<DT>
14664<A HREF="file:~/.bash_logout"><I>~/.bash_logout</I></A>
14665
14666<DD>
14667The individual login shell cleanup file, executed when a login shell exits
14668<DT>
74091dd4
CR
14669<A HREF="file:~/.bash_history"><I>~/.bash_history</I></A>
14670
14671<DD>
14672The default value of <B>HISTFILE</B>, the file in which bash saves the
14673command history
14674<DT>
17345e5a
JA
14675<A HREF="file:~/.inputrc"><I>~/.inputrc</I></A>
14676
14677<DD>
14678Individual <I>readline</I> initialization file
14679
14680</DL>
8868edaf 14681<A NAME="lbDG">&nbsp;</A>
17345e5a
JA
14682<H3>AUTHORS</H3>
14683
14684Brian Fox, Free Software Foundation
14685<BR>
14686
14687<A HREF="mailto:bfox@gnu.org">bfox@gnu.org</A>
14688<P>
14689
14690Chet Ramey, Case Western Reserve University
14691<BR>
14692
0001803f 14693<A HREF="mailto:chet.ramey@case.edu">chet.ramey@case.edu</A>
8868edaf 14694<A NAME="lbDH">&nbsp;</A>
17345e5a
JA
14695<H3>BUG REPORTS</H3>
14696
14697If you find a bug in
14698<B>bash,</B>
14699
14700you should report it. But first, you should
14701make sure that it really is a bug, and that it appears in the latest
14702version of
14703<B>bash</B>.
14704
14705The latest version is always available from
74091dd4
CR
14706<I><A HREF="ftp://ftp.gnu.org/pub/gnu/bash/">ftp://ftp.gnu.org/pub/gnu/bash/</A></I> and
14707<I><A HREF="http://git.savannah.gnu.org/cgit/bash.git/snapshot/bash-master.tar.gz">http://git.savannah.gnu.org/cgit/bash.git/snapshot/bash-master.tar.gz</A></I>.
17345e5a
JA
14708<P>
14709
14710Once you have determined that a bug actually exists, use the
14711<I>bashbug</I>
14712
14713command to submit a bug report.
14714If you have a fix, you are encouraged to mail that as well!
14715Suggestions and `philosophical' bug reports may be mailed
14716to <I><A HREF="mailto:bug-bash@gnu.org">bug-bash@gnu.org</A></I> or posted to the Usenet
14717newsgroup
14718<A HREF="news:gnu.bash.bug">gnu.bash.bug</A>.
14719
14720<P>
14721
14722ALL bug reports should include:
14723<P>
14724
14725
14726<DL COMPACT>
14727<DT>The version number of <B>bash</B><DD>
14728<DT>The hardware and operating system<DD>
14729<DT>The compiler used to compile<DD>
14730<DT>A description of the bug behaviour<DD>
14731<DT>A short script or `recipe' which exercises the bug<DD>
14732
14733</DL>
14734<P>
14735
14736<I>bashbug</I>
14737
14738inserts the first three items automatically into the template
14739it provides for filing a bug report.
14740<P>
14741
14742Comments and bug reports concerning
14743this manual page should be directed to
ac50fbac 14744<I><A HREF="mailto:chet.ramey@case.edu">chet.ramey@case.edu</A></I>.
17345e5a 14745
8868edaf 14746<A NAME="lbDI">&nbsp;</A>
17345e5a
JA
14747<H3>BUGS</H3>
14748
17345e5a
JA
14749It's too big and too slow.
14750<P>
14751
a0c0a00f 14752There are some subtle differences between
17345e5a
JA
14753<B>bash</B>
14754
14755and traditional versions of
14756<B>sh</B>,
14757
14758mostly because of the
14759<FONT SIZE=-1><B>POSIX</B>
14760
14761</FONT>
14762specification.
14763<P>
14764
14765Aliases are confusing in some uses.
14766<P>
14767
14768Shell builtin commands and functions are not stoppable/restartable.
14769<P>
14770
14771Compound commands and command sequences of the form `a ; b ; c'
14772are not handled gracefully when process suspension is attempted.
14773When a process is stopped, the shell immediately executes the next
14774command in the sequence.
14775It suffices to place the sequence of commands between
14776parentheses to force it into a subshell, which may be stopped as
14777a unit.
14778<P>
14779
14780Array variables may not (yet) be exported.
14781<P>
14782
14783There may be only one active coprocess at a time.
14784
14785
14786
14787<HR>
14788<TABLE WIDTH=100%>
14789<TR>
74091dd4 14790<TH ALIGN=LEFT width=33%>GNU Bash 5.2<TH ALIGN=CENTER width=33%>2022 September 19<TH ALIGN=RIGHT width=33%>BASH(1)
17345e5a
JA
14791</TR>
14792</TABLE>
14793<HR>
14794<A NAME="index">&nbsp;</A><H2>Index</H2>
14795<DL>
14796<DT><A HREF="#lbAB">NAME</A><DD>
14797<DT><A HREF="#lbAC">SYNOPSIS</A><DD>
14798<DT><A HREF="#lbAD">COPYRIGHT</A><DD>
14799<DT><A HREF="#lbAE">DESCRIPTION</A><DD>
14800<DT><A HREF="#lbAF">OPTIONS</A><DD>
14801<DT><A HREF="#lbAG">ARGUMENTS</A><DD>
14802<DT><A HREF="#lbAH">INVOCATION</A><DD>
14803<DT><A HREF="#lbAI">DEFINITIONS</A><DD>
14804<DT><A HREF="#lbAJ">RESERVED WORDS</A><DD>
14805<DT><A HREF="#lbAK">SHELL GRAMMAR</A><DD>
14806<DL>
14807<DT><A HREF="#lbAL">Simple Commands</A><DD>
14808<DT><A HREF="#lbAM">Pipelines</A><DD>
14809<DT><A HREF="#lbAN">Lists</A><DD>
14810<DT><A HREF="#lbAO">Compound Commands</A><DD>
14811<DT><A HREF="#lbAP">Coprocesses</A><DD>
14812<DT><A HREF="#lbAQ">Shell Function Definitions</A><DD>
14813</DL>
14814<DT><A HREF="#lbAR">COMMENTS</A><DD>
14815<DT><A HREF="#lbAS">QUOTING</A><DD>
14816<DT><A HREF="#lbAT">PARAMETERS</A><DD>
14817<DL>
14818<DT><A HREF="#lbAU">Positional Parameters</A><DD>
14819<DT><A HREF="#lbAV">Special Parameters</A><DD>
14820<DT><A HREF="#lbAW">Shell Variables</A><DD>
14821<DT><A HREF="#lbAX">Arrays</A><DD>
14822</DL>
14823<DT><A HREF="#lbAY">EXPANSION</A><DD>
14824<DL>
14825<DT><A HREF="#lbAZ">Brace Expansion</A><DD>
14826<DT><A HREF="#lbBA">Tilde Expansion</A><DD>
14827<DT><A HREF="#lbBB">Parameter Expansion</A><DD>
14828<DT><A HREF="#lbBC">Command Substitution</A><DD>
14829<DT><A HREF="#lbBD">Arithmetic Expansion</A><DD>
14830<DT><A HREF="#lbBE">Process Substitution</A><DD>
14831<DT><A HREF="#lbBF">Word Splitting</A><DD>
14832<DT><A HREF="#lbBG">Pathname Expansion</A><DD>
14833<DT><A HREF="#lbBH">Quote Removal</A><DD>
14834</DL>
14835<DT><A HREF="#lbBI">REDIRECTION</A><DD>
14836<DL>
14837<DT><A HREF="#lbBJ">Redirecting Input</A><DD>
14838<DT><A HREF="#lbBK">Redirecting Output</A><DD>
14839<DT><A HREF="#lbBL">Appending Redirected Output</A><DD>
14840<DT><A HREF="#lbBM">Redirecting Standard Output and Standard Error</A><DD>
14841<DT><A HREF="#lbBN">Appending Standard Output and Standard Error</A><DD>
14842<DT><A HREF="#lbBO">Here Documents</A><DD>
14843<DT><A HREF="#lbBP">Here Strings</A><DD>
14844<DT><A HREF="#lbBQ">Duplicating File Descriptors</A><DD>
14845<DT><A HREF="#lbBR">Moving File Descriptors</A><DD>
14846<DT><A HREF="#lbBS">Opening File Descriptors for Reading and Writing</A><DD>
14847</DL>
14848<DT><A HREF="#lbBT">ALIASES</A><DD>
14849<DT><A HREF="#lbBU">FUNCTIONS</A><DD>
14850<DT><A HREF="#lbBV">ARITHMETIC EVALUATION</A><DD>
14851<DT><A HREF="#lbBW">CONDITIONAL EXPRESSIONS</A><DD>
14852<DT><A HREF="#lbBX">SIMPLE COMMAND EXPANSION</A><DD>
14853<DT><A HREF="#lbBY">COMMAND EXECUTION</A><DD>
14854<DT><A HREF="#lbBZ">COMMAND EXECUTION ENVIRONMENT</A><DD>
14855<DT><A HREF="#lbCA">ENVIRONMENT</A><DD>
14856<DT><A HREF="#lbCB">EXIT STATUS</A><DD>
14857<DT><A HREF="#lbCC">SIGNALS</A><DD>
14858<DT><A HREF="#lbCD">JOB CONTROL</A><DD>
14859<DT><A HREF="#lbCE">PROMPTING</A><DD>
14860<DT><A HREF="#lbCF">READLINE</A><DD>
14861<DL>
14862<DT><A HREF="#lbCG">Readline Notation</A><DD>
14863<DT><A HREF="#lbCH">Readline Initialization</A><DD>
14864<DT><A HREF="#lbCI">Readline Key Bindings</A><DD>
14865<DT><A HREF="#lbCJ">Readline Variables</A><DD>
14866<DT><A HREF="#lbCK">Readline Conditional Constructs</A><DD>
14867<DT><A HREF="#lbCL">Searching</A><DD>
14868<DT><A HREF="#lbCM">Readline Command Names</A><DD>
14869<DT><A HREF="#lbCN">Commands for Moving</A><DD>
14870<DT><A HREF="#lbCO">Commands for Manipulating the History</A><DD>
14871<DT><A HREF="#lbCP">Commands for Changing Text</A><DD>
14872<DT><A HREF="#lbCQ">Killing and Yanking</A><DD>
14873<DT><A HREF="#lbCR">Numeric Arguments</A><DD>
14874<DT><A HREF="#lbCS">Completing</A><DD>
14875<DT><A HREF="#lbCT">Keyboard Macros</A><DD>
14876<DT><A HREF="#lbCU">Miscellaneous</A><DD>
14877<DT><A HREF="#lbCV">Programmable Completion</A><DD>
14878</DL>
14879<DT><A HREF="#lbCW">HISTORY</A><DD>
14880<DT><A HREF="#lbCX">HISTORY EXPANSION</A><DD>
14881<DL>
14882<DT><A HREF="#lbCY">Event Designators</A><DD>
14883<DT><A HREF="#lbCZ">Word Designators</A><DD>
14884<DT><A HREF="#lbDA">Modifiers</A><DD>
14885</DL>
14886<DT><A HREF="#lbDB">SHELL BUILTIN COMMANDS</A><DD>
8868edaf
CR
14887<DT><A HREF="#lbDC">SHELL COMPATIBILITY MODE</A><DD>
14888<DT><A HREF="#lbDD">RESTRICTED SHELL</A><DD>
14889<DT><A HREF="#lbDE">SEE ALSO</A><DD>
14890<DT><A HREF="#lbDF">FILES</A><DD>
14891<DT><A HREF="#lbDG">AUTHORS</A><DD>
14892<DT><A HREF="#lbDH">BUG REPORTS</A><DD>
14893<DT><A HREF="#lbDI">BUGS</A><DD>
17345e5a
JA
14894</DL>
14895<HR>
74091dd4
CR
14896This document was created by man2html from /usr/local/src/bash/bash-20220907/doc/bash.1.<BR>
14897Time: 19 September 2022 12:02:51 EDT
17345e5a
JA
14898</BODY>
14899</HTML>