This repository was archived by the owner on Nov 20, 2024. It is now read-only.
forked from bminor/bash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbash.1
11764 lines (11764 loc) · 343 KB
/
bash.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
.\"
.\" MAN PAGE COMMENTS to
.\"
.\" Chet Ramey
.\" Case Western Reserve University
.\"
.\" Last Change: Mon Sep 19 11:13:21 EDT 2022
.\"
.\" bash_builtins, strip all but Built-Ins section
.if \n(zZ=1 .ig zZ
.if \n(zY=1 .ig zY
.TH BASH 1 "2022 September 19" "GNU Bash 5.2"
.\"
.\" There's some problem with having a `@'
.\" in a tagged paragraph with the BSD man macros.
.\" It has to do with `@' appearing in the }1 macro.
.\" This is a problem on 4.3 BSD and Ultrix, but Sun
.\" appears to have fixed it.
.\" If you're seeing the characters
.\" `@u-3p' appearing before the lines reading
.\" `possible-hostname-completions
.\" and `complete-hostname' down in READLINE,
.\" then uncomment this redefinition.
.\"
.\" .de }1
.\" .ds ]X \&\\*(]B\\
.\" .nr )E 0
.\" .if !"\\$1"" .nr )I \\$1n
.\" .}f
.\" .ll \\n(LLu
.\" .in \\n()Ru+\\n(INu+\\n()Iu
.\" .ti \\n(INu
.\" .ie !\\n()Iu+\\n()Ru-\w\\*(]Xu-3p \{\\*(]X
.\" .br\}
.\" .el \\*(]X\h|\\n()Iu+\\n()Ru\c
.\" .}f
.\" ..
.\"
.\" File Name macro. This used to be `.PN', for Path Name,
.\" but Sun doesn't seem to like that very much.
.\"
.de FN
\fI\|\\$1\|\fP
..
.SH NAME
bash \- GNU Bourne-Again SHell
.SH SYNOPSIS
.B bash
[options]
[command_string | file]
.SH COPYRIGHT
.if n Bash is Copyright (C) 1989-2022 by the Free Software Foundation, Inc.
.if t Bash is Copyright \(co 1989-2022 by the Free Software Foundation, Inc.
.SH DESCRIPTION
.B Bash
is an \fBsh\fR-compatible command language interpreter that
executes commands read from the standard input or from a file.
.B Bash
also incorporates useful features from the \fIKorn\fP and \fIC\fP
shells (\fBksh\fP and \fBcsh\fP).
.PP
.B Bash
is intended to be a conformant implementation of the
Shell and Utilities portion of the IEEE POSIX specification
(IEEE Standard 1003.1).
.B Bash
can be configured to be POSIX-conformant by default.
.SH OPTIONS
All of the single-character shell options documented in the
description of the \fBset\fR builtin command, including \fB\-o\fP,
can be used as options when the shell is invoked.
In addition, \fBbash\fR
interprets the following options when it is invoked:
.PP
.PD 0
.TP 10
.B \-c
If the
.B \-c
option is present, then commands are read from the first non-option argument
.IR command_string .
If there are arguments after the
.IR command_string ,
the first argument is assigned to
.B $0
and any remaining arguments are assigned to the positional parameters.
The assignment to
.B $0
sets the name of the shell, which is used in warning and error messages.
.TP
.B \-i
If the
.B \-i
option is present, the shell is
.IR interactive .
.TP
.B \-l
Make
.B bash
act as if it had been invoked as a login shell (see
.SM
.B INVOCATION
below).
.TP
.B \-r
If the
.B \-r
option is present, the shell becomes
.I restricted
(see
.SM
.B "RESTRICTED SHELL"
below).
.TP
.B \-s
If the
.B \-s
option is present, or if no arguments remain after option
processing, then commands are read from the standard input.
This option allows the positional parameters to be set
when invoking an interactive shell or when reading input
through a pipe.
.TP
.B \-D
A list of all double-quoted strings preceded by \fB$\fP
is printed on the standard output.
These are the strings that
are subject to language translation when the current locale
is not \fBC\fP or \fBPOSIX\fP.
This implies the \fB\-n\fP option; no commands will be executed.
.TP
.B [\-+]O [\fIshopt_option\fP]
\fIshopt_option\fP is one of the shell options accepted by the
\fBshopt\fP builtin (see
.SM
.B SHELL BUILTIN COMMANDS
below).
If \fIshopt_option\fP is present, \fB\-O\fP sets the value of that option;
\fB+O\fP unsets it.
If \fIshopt_option\fP is not supplied, the names and values of the shell
options accepted by \fBshopt\fP are printed on the standard output.
If the invocation option is \fB+O\fP, the output is displayed in a format
that may be reused as input.
.TP
.B \-\-
A
.B \-\-
signals the end of options and disables further option processing.
Any arguments after the
.B \-\-
are treated as filenames and arguments. An argument of
.B \-
is equivalent to \fB\-\-\fP.
.PD
.PP
.B Bash
also interprets a number of multi-character options.
These options must appear on the command line before the
single-character options to be recognized.
.PP
.PD 0
.TP
.B \-\-debugger
Arrange for the debugger profile to be executed before the shell
starts.
Turns on extended debugging mode (see the description of the
.B extdebug
option to the
.B shopt
builtin below).
.TP
.B \-\-dump\-po\-strings
Equivalent to \fB\-D\fP, but the output is in the GNU \fIgettext\fP
\fBpo\fP (portable object) file format.
.TP
.B \-\-dump\-strings
Equivalent to \fB\-D\fP.
.TP
.B \-\-help
Display a usage message on standard output and exit successfully.
.TP
\fB\-\-init\-file\fP \fIfile\fP
.PD 0
.TP
\fB\-\-rcfile\fP \fIfile\fP
.PD
Execute commands from
.I file
instead of the standard personal initialization file
.I ~/.bashrc
if the shell is interactive (see
.SM
.B INVOCATION
below).
.TP
.B \-\-login
Equivalent to \fB\-l\fP.
.TP
.B \-\-noediting
Do not use the GNU
.B readline
library to read command lines when the shell is interactive.
.TP
.B \-\-noprofile
Do not read either the system-wide startup file
.FN /etc/profile
or any of the personal initialization files
.IR ~/.bash_profile ,
.IR ~/.bash_login ,
or
.IR ~/.profile .
By default,
.B bash
reads these files when it is invoked as a login shell (see
.SM
.B INVOCATION
below).
.TP
.B \-\-norc
Do not read and execute the personal initialization file
.I ~/.bashrc
if the shell is interactive.
This option is on by default if the shell is invoked as
.BR sh .
.TP
.B \-\-posix
Change the behavior of \fBbash\fP where the default operation differs
from the POSIX standard to match the standard (\fIposix mode\fP).
See
.SM
.B "SEE ALSO"
below for a reference to a document that details how posix mode affects
bash's behavior.
.TP
.B \-\-restricted
The shell becomes restricted (see
.SM
.B "RESTRICTED SHELL"
below).
.TP
.B \-\-verbose
Equivalent to \fB\-v\fP.
.TP
.B \-\-version
Show version information for this instance of
.B bash
on the standard output and exit successfully.
.PD
.SH ARGUMENTS
If arguments remain after option processing, and neither the
.B \-c
nor the
.B \-s
option has been supplied, the first argument is assumed to
be the name of a file containing shell commands.
If
.B bash
is invoked in this fashion,
.B $0
is set to the name of the file, and the positional parameters
are set to the remaining arguments.
.B Bash
reads and executes commands from this file, then exits.
\fBBash\fP's exit status is the exit status of the last command
executed in the script.
If no commands are executed, the exit status is 0.
An attempt is first made to open the file in the current directory, and,
if no file is found, then the shell searches the directories in
.SM
.B PATH
for the script.
.SH INVOCATION
A \fIlogin shell\fP is one whose first character of argument zero is a
.BR \- ,
or one started with the
.B \-\-login
option.
.PP
An \fIinteractive\fP shell is one started without non-option arguments
(unless \fB\-s\fP is specified)
and without the
.B \-c
option,
whose standard input and error are
both connected to terminals (as determined by
.IR isatty (3)),
or one started with the
.B \-i
option.
.SM
.B PS1
is set and
.B $\-
includes
.B i
if
.B bash
is interactive,
allowing a shell script or a startup file to test this state.
.PP
The following paragraphs describe how
.B bash
executes its startup files.
If any of the files exist but cannot be read,
.B bash
reports an error.
Tildes are expanded in filenames as described below under
.B "Tilde Expansion"
in the
.SM
.B EXPANSION
section.
.PP
When
.B bash
is invoked as an interactive login shell, or as a non-interactive shell
with the \fB\-\-login\fP option, it first reads and
executes commands from the file \fI/etc/profile\fP, if that
file exists.
After reading that file, it looks for \fI~/.bash_profile\fP,
\fI~/.bash_login\fP, and \fI~/.profile\fP, in that order, and reads
and executes commands from the first one that exists and is readable.
The
.B \-\-noprofile
option may be used when the shell is started to inhibit this behavior.
.PP
When an interactive login shell exits,
or a non-interactive login shell executes the \fBexit\fP builtin command,
.B bash
reads and executes commands from the file \fI~/.bash_logout\fP, if it
exists.
.PP
When an interactive shell that is not a login shell is started,
.B bash
reads and executes commands from \fI~/.bashrc\fP, if that file exists.
This may be inhibited by using the
.B \-\-norc
option.
The \fB\-\-rcfile\fP \fIfile\fP option will force
.B bash
to read and execute commands from \fIfile\fP instead of \fI~/.bashrc\fP.
.PP
When
.B bash
is started non-interactively, to run a shell script, for example, it
looks for the variable
.SM
.B BASH_ENV
in the environment, expands its value if it appears there, and uses the
expanded value as the name of a file to read and execute.
.B Bash
behaves as if the following command were executed:
.sp .5
.RS
.if t \f(CWif [ \-n "$BASH_ENV" ]; then . "$BASH_ENV"; fi\fP
.if n if [ \-n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
.RE
.sp .5
but the value of the
.SM
.B PATH
variable is not used to search for the filename.
.PP
If
.B bash
is invoked with the name
.BR sh ,
it tries to mimic the startup behavior of historical versions of
.B sh
as closely as possible,
while conforming to the POSIX standard as well.
When invoked as an interactive login shell, or a non-interactive
shell with the \fB\-\-login\fP option, it first attempts to
read and execute commands from
.I /etc/profile
and
.IR ~/.profile ,
in that order.
The
.B \-\-noprofile
option may be used to inhibit this behavior.
When invoked as an interactive shell with the name
.BR sh ,
.B bash
looks for the variable
.SM
.BR ENV ,
expands its value if it is defined, and uses the
expanded value as the name of a file to read and execute.
Since a shell invoked as
.B sh
does not attempt to read and execute commands from any other startup
files, the
.B \-\-rcfile
option has no effect.
A non-interactive shell invoked with the name
.B sh
does not attempt to read any other startup files.
When invoked as
.BR sh ,
.B bash
enters
.I posix
mode after the startup files are read.
.PP
When
.B bash
is started in
.I posix
mode, as with the
.B \-\-posix
command line option, it follows the POSIX standard for startup files.
In this mode, interactive shells expand the
.SM
.B ENV
variable and commands are read and executed from the file
whose name is the expanded value.
No other startup files are read.
.PP
.B Bash
attempts to determine when it is being run with its standard input
connected to a network connection, as when executed by
the historical remote shell daemon, usually \fIrshd\fP,
or the secure shell daemon \fIsshd\fP.
If
.B bash
determines it is being run non-interactively in this fashion,
it reads and executes commands from \fI~/.bashrc\fP,
if that file exists and is readable.
It will not do this if invoked as \fBsh\fP.
The
.B \-\-norc
option may be used to inhibit this behavior, and the
.B \-\-rcfile
option may be used to force another file to be read, but neither
\fIrshd\fP nor \fIsshd\fP generally invoke the shell with those options
or allow them to be specified.
.PP
If the shell is started with the effective user (group) id not equal to the
real user (group) id, and the \fB\-p\fP option is not supplied, no startup
files are read, shell functions are not inherited from the environment, the
.SM
.BR SHELLOPTS ,
.SM
.BR BASHOPTS ,
.SM
.BR CDPATH ,
and
.SM
.B GLOBIGNORE
variables, if they appear in the environment, are ignored,
and the effective user id is set to the real user id.
If the \fB\-p\fP option is supplied at invocation, the startup behavior is
the same, but the effective user id is not reset.
.SH DEFINITIONS
The following definitions are used throughout the rest of this
document.
.PD 0
.TP
.B blank
A space or tab.
.TP
.B word
A sequence of characters considered as a single unit by the shell.
Also known as a
.BR token .
.TP
.B name
A
.I word
consisting only of alphanumeric characters and underscores, and
beginning with an alphabetic character or an underscore. Also
referred to as an
.BR identifier .
.TP
.B metacharacter
A character that, when unquoted, separates words. One of the following:
.br
.RS
.PP
.if t \fB| & ; ( ) < > space tab newline\fP
.if n \fB| & ; ( ) < > space tab newline\fP
.RE
.TP
.B control operator
A \fItoken\fP that performs a control function. It is one of the following
symbols:
.RS
.PP
.if t \fB|| & && ; ;; ;& ;;& ( ) | |& <newline>\fP
.if n \fB|| & && ; ;; ;& ;;& ( ) | |& <newline>\fP
.RE
.PD
.SH "RESERVED WORDS"
\fIReserved words\fP are words that have a special meaning to the shell.
The following words are recognized as reserved when unquoted and either
the first word of a command (see
.SM
.B SHELL GRAMMAR
below), the third word of a
.B case
or
.B select
command
(only \fBin\fP is valid), or the third word of a
.B for
command (only \fBin\fP and \fBdo\fP are valid):
.if t .RS
.PP
.B
.if n ! case coproc do done elif else esac fi for function if in select then until while { } time [[ ]]
.if t ! case coproc do done elif else esac fi for function if in select then until while { } time [[ ]]
.if t .RE
.SH "SHELL GRAMMAR"
This section describes the syntax of the various forms of shell commands.
.SS Simple Commands
A \fIsimple command\fP is a sequence of optional variable assignments
followed by \fBblank\fP-separated words and redirections, and
terminated by a \fIcontrol operator\fP. The first word
specifies the command to be executed, and is passed as argument zero.
The remaining words are passed as arguments to the invoked command.
.PP
The return value of a \fIsimple command\fP is its exit status, or
128+\fIn\^\fP if the command is terminated by signal
.IR n .
.SS Pipelines
A \fIpipeline\fP is a sequence of one or more commands separated by
one of the control operators
.B |
or \fB|&\fP.
The format for a pipeline is:
.RS
.PP
[\fBtime\fP [\fB\-p\fP]] [ ! ] \fIcommand1\fP [ [\fB|\fP\(bv\fB|&\fP] \fIcommand2\fP ... ]
.RE
.PP
The standard output of
.I command1
is connected via a pipe to the standard input of
.IR command2 .
This connection is performed before any redirections specified by the
.IR command1 (see
.SM
.B REDIRECTION
below).
If \fB|&\fP is used, \fIcommand1\fP's standard error, in addition to its
standard output, is connected to
\fIcommand2\fP's standard input through the pipe;
it is shorthand for \fB2>&1 |\fP.
This implicit redirection of the standard error to the standard output is
performed after any redirections specified by \fIcommand1\fP.
.PP
The return status of a pipeline is the exit status of the last
command, unless the \fBpipefail\fP option is enabled.
If \fBpipefail\fP is enabled, the pipeline's return status is the
value of the last (rightmost) command to exit with a non-zero status,
or zero if all commands exit successfully.
If the reserved word
.B !
precedes a pipeline, the exit status of that pipeline is the logical
negation of the exit status as described above.
The shell waits for all commands in the pipeline to
terminate before returning a value.
.PP
If the
.B time
reserved word precedes a pipeline, the elapsed as well as user and
system time consumed by its execution are reported when the pipeline
terminates.
The \fB\-p\fP option changes the output format to that specified by POSIX.
When the shell is in \fIposix mode\fP, it does not recognize
\fBtime\fP as a reserved word if the next token begins with a `-'.
The
.SM
.B TIMEFORMAT
variable may be set to a format string that specifies how the timing
information should be displayed; see the description of
.SM
.B TIMEFORMAT
under
.B "Shell Variables"
below.
.PP
When the shell is in \fIposix mode\fP, \fBtime\fP
may be followed by a newline. In this case, the shell displays the
total user and system time consumed by the shell and its children.
The
.SM
.B TIMEFORMAT
variable may be used to specify the format of
the time information.
.PP
Each command in a multi-command pipeline,
where pipes are created,
is executed in a \fIsubshell\fP, which is a
separate process.
See
.SM
\fBCOMMAND EXECUTION ENVIRONMENT\fP
for a description of subshells and a subshell environment.
If the \fBlastpipe\fP option is enabled using the \fBshopt\fP builtin
(see the description of \fBshopt\fP below),
the last element of a pipeline may be run by the shell process
when job control is not active.
.SS Lists
A \fIlist\fP is a sequence of one or more pipelines separated by one
of the operators
.BR ; ,
.BR & ,
.BR && ,
or
.BR || ,
and optionally terminated by one of
.BR ; ,
.BR & ,
or
.BR <newline> .
.PP
Of these list operators,
.B &&
and
.B ||
have equal precedence, followed by
.B ;
and
.BR & ,
which have equal precedence.
.PP
A sequence of one or more newlines may appear in a \fIlist\fP instead
of a semicolon to delimit commands.
.PP
If a command is terminated by the control operator
.BR & ,
the shell executes the command in the \fIbackground\fP
in a subshell.
The shell does not wait for the command to
finish, and the return status is 0.
These are referred to as \fIasynchronous\fP commands.
Commands separated by a
.B ;
are executed sequentially; the shell waits for each
command to terminate in turn. The return status is the
exit status of the last command executed.
.PP
AND and OR lists are sequences of one or more pipelines separated by the
\fB&&\fP and \fB||\fP control operators, respectively.
AND and OR lists are executed with left associativity.
An AND list has the form
.RS
.PP
\fIcommand1\fP \fB&&\fP \fIcommand2\fP
.RE
.PP
.I command2
is executed if, and only if,
.I command1
returns an exit status of zero (success).
.PP
An OR list has the form
.RS
.PP
\fIcommand1\fP \fB||\fP \fIcommand2\fP
.RE
.PP
.I command2
is executed if, and only if,
.I command1
returns a non-zero exit status.
The return status of
AND and OR lists is the exit status of the last command
executed in the list.
.SS Compound Commands
A \fIcompound command\fP is one of the following.
In most cases a \fIlist\fP in a command's description may be separated from
the rest of the command by one or more newlines, and may be followed by a
newline in place of a semicolon.
.TP
(\fIlist\fP)
\fIlist\fP is executed in a subshell (see
.SM
\fBCOMMAND EXECUTION ENVIRONMENT\fP
below for a description of a subshell environment).
Variable assignments and builtin
commands that affect the shell's environment do not remain in effect
after the command completes. The return status is the exit status of
\fIlist\fP.
.TP
{ \fIlist\fP; }
\fIlist\fP is simply executed in the current shell environment.
\fIlist\fP must be terminated with a newline or semicolon.
This is known as a \fIgroup command\fP.
The return status is the exit status of
\fIlist\fP.
Note that unlike the metacharacters \fB(\fP and \fB)\fP, \fB{\fP and
\fB}\fP are \fIreserved words\fP and must occur where a reserved
word is permitted to be recognized. Since they do not cause a word
break, they must be separated from \fIlist\fP by whitespace or another
shell metacharacter.
.TP
((\fIexpression\fP))
The \fIexpression\fP is evaluated according to the rules described
below under
.SM
.BR "ARITHMETIC EVALUATION" .
If the value of the expression is non-zero, the return status is 0;
otherwise the return status is 1.
The \fIexpression\fP
undergoes the same expansions
as if it were within double quotes,
but double quote characters in \fIexpression\fP are not treated specially
and are removed.
.TP
\fB[[\fP \fIexpression\fP \fB]]\fP
Return a status of 0 or 1 depending on the evaluation of
the conditional expression \fIexpression\fP.
Expressions are composed of the primaries described below under
.SM
.BR "CONDITIONAL EXPRESSIONS" .
The words between the \fB[[\fP and \fB]]\fP do not undergo word splitting
and pathname expansion.
The shell performs tilde expansion, parameter and
variable expansion, arithmetic expansion, command substitution, process
substitution, and quote removal on those words
(the expansions that would occur if the words were enclosed in double quotes).
Conditional operators such as \fB\-f\fP must be unquoted to be recognized
as primaries.
.if t .sp 0.5
.if n .sp 1
When used with \fB[[\fP, the \fB<\fP and \fB>\fP operators sort
lexicographically using the current locale.
.if t .sp 0.5
.if n .sp 1
When the \fB==\fP and \fB!=\fP operators are used, the string to the
right of the operator is considered a pattern and matched according
to the rules described below under \fBPattern Matching\fP,
as if the \fBextglob\fP shell option were enabled.
The \fB=\fP operator is equivalent to \fB==\fP.
If the
.B nocasematch
shell option is enabled, the match is performed without regard to the case
of alphabetic characters.
The return value is 0 if the string matches (\fB==\fP) or does not match
(\fB!=\fP) the pattern, and 1 otherwise.
Any part of the pattern may be quoted to force the quoted portion
to be matched as a string.
.if t .sp 0.5
.if n .sp 1
An additional binary operator, \fB=~\fP, is available, with the same
precedence as \fB==\fP and \fB!=\fP.
When it is used, the string to the right of the operator is considered
a POSIX extended regular expression and matched accordingly
(using the POSIX \fIregcomp\fP and \fIregexec\fP interfaces
usually described in \fIregex\fP(3)).
The return value is 0 if the string matches
the pattern, and 1 otherwise.
If the regular expression is syntactically incorrect, the conditional
expression's return value is 2.
If the
.B nocasematch
shell option is enabled, the match is performed without regard to the case
of alphabetic characters.
If any part of the pattern is quoted, the quoted portion is matched literally.
This means every character in the quoted portion matches itself,
instead of having any special pattern matching meaning.
If the pattern is stored in a shell variable, quoting the variable
expansion forces the entire pattern to be matched literally.
Treat bracket expressions in regular expressions carefully,
since normal quoting and pattern characters lose their meanings
between brackets.
.if t .sp 0.5
.if n .sp 1
The pattern will match if it matches any part of the string.
Anchor the pattern using the \fB^\fP and \fB$\fP regular expression
operators to force it to match the entire string.
The array variable
.SM
.B BASH_REMATCH
records which parts of the string matched the pattern.
The element of
.SM
.B BASH_REMATCH
with index 0 contains the portion of
the string matching the entire regular expression.
Substrings matched by parenthesized subexpressions within the regular
expression are saved in the remaining
.SM
.B BASH_REMATCH
indices. The element of
.SM
.B BASH_REMATCH
with index \fIn\fP is the portion of the
string matching the \fIn\fPth parenthesized subexpression.
Bash sets
.SM
.B BASH_REMATCH
in the global scope; declaring it as a local variable will lead to
unexpected results.
.if t .sp 0.5
.if n .sp 1
Expressions may be combined using the following operators, listed
in decreasing order of precedence:
.if t .sp 0.5
.if n .sp 1
.RS
.PD 0
.TP
.B ( \fIexpression\fP )
Returns the value of \fIexpression\fP.
This may be used to override the normal precedence of operators.
.TP
.B ! \fIexpression\fP
True if
.I expression
is false.
.TP
\fIexpression1\fP \fB&&\fP \fIexpression2\fP
True if both
.I expression1
and
.I expression2
are true.
.TP
\fIexpression1\fP \fB||\fP \fIexpression2\fP
True if either
.I expression1
or
.I expression2
is true.
.PD
.LP
The \fB&&\fP and \fB||\fP
operators do not evaluate \fIexpression2\fP if the value of
\fIexpression1\fP is sufficient to determine the return value of
the entire conditional expression.
.RE
.TP
\fBfor\fP \fIname\fP [ [ \fBin\fP [ \fIword ...\fP ] ] ; ] \fBdo\fP \fIlist\fP ; \fBdone\fP
The list of words following \fBin\fP is expanded, generating a list
of items.
The variable \fIname\fP is set to each element of this list
in turn, and \fIlist\fP is executed each time.
If the \fBin\fP \fIword\fP is omitted, the \fBfor\fP command executes
\fIlist\fP once for each positional parameter that is set (see
.SM
.B PARAMETERS
below).
The return status is the exit status of the last command that executes.
If the expansion of the items following \fBin\fP results in an empty
list, no commands are executed, and the return status is 0.
.TP
\fBfor\fP (( \fIexpr1\fP ; \fIexpr2\fP ; \fIexpr3\fP )) ; \fBdo\fP \fIlist\fP ; \fBdone\fP
First, the arithmetic expression \fIexpr1\fP is evaluated according
to the rules described below under
.SM
.BR "ARITHMETIC EVALUATION" .
The arithmetic expression \fIexpr2\fP is then evaluated repeatedly
until it evaluates to zero.
Each time \fIexpr2\fP evaluates to a non-zero value, \fIlist\fP is
executed and the arithmetic expression \fIexpr3\fP is evaluated.
If any expression is omitted, it behaves as if it evaluates to 1.
The return value is the exit status of the last command in \fIlist\fP
that is executed, or false if any of the expressions is invalid.
.TP
\fBselect\fP \fIname\fP [ \fBin\fP \fIword\fP ] ; \fBdo\fP \fIlist\fP ; \fBdone\fP
The list of words following \fBin\fP is expanded, generating a list
of items, and the set of expanded words is printed on the standard
error, each preceded by a number. If the \fBin\fP
\fIword\fP is omitted, the positional parameters are printed (see
.SM
.B PARAMETERS
below).
.B select
then displays the
.SM
.B PS3
prompt and reads a line from the standard input.
If the line consists of a number corresponding to one of
the displayed words, then the value of
.I name
is set to that word.
If the line is empty, the words and prompt are displayed again.
If EOF is read, the \fBselect\fP command completes and returns 1.
Any other value read causes
.I name
to be set to null. The line read is saved in the variable
.SM
.BR REPLY .
The
.I list
is executed after each selection until a
.B break
command is executed.
The exit status of
.B select
is the exit status of the last command executed in
.IR list ,
or zero if no commands were executed.
.TP
\fBcase\fP \fIword\fP \fBin\fP [ [(] \fIpattern\fP [ \fB|\fP \fIpattern\fP ] \
... ) \fIlist\fP ;; ] ... \fBesac\fP
A \fBcase\fP command first expands \fIword\fP, and tries to match
it against each \fIpattern\fP in turn, using the matching rules
described under
.B Pattern Matching
below.
The \fIword\fP is expanded using tilde
expansion, parameter and variable expansion, arithmetic expansion,
command substitution, process substitution and quote removal.
Each \fIpattern\fP examined is expanded using tilde
expansion, parameter and variable expansion, arithmetic expansion,
command substitution, process substitution, and quote removal.
If the
.B nocasematch
shell option is enabled, the match is performed without regard to the case
of alphabetic characters.
When a match is found, the corresponding \fIlist\fP is executed.
If the \fB;;\fP operator is used, no subsequent matches are attempted after
the first pattern match.
Using \fB;&\fP in place of \fB;;\fP causes execution to continue with
the \fIlist\fP associated with the next set of patterns.
Using \fB;;&\fP in place of \fB;;\fP causes the shell to test the next
pattern list in the statement, if any, and execute any associated \fIlist\fP
on a successful match,
continuing the case statement execution as if the pattern list had not matched.
The exit status is zero if no
pattern matches. Otherwise, it is the exit status of the
last command executed in \fIlist\fP.
.TP
\fBif\fP \fIlist\fP; \fBthen\fP \fIlist\fP; \
[ \fBelif\fP \fIlist\fP; \fBthen\fP \fIlist\fP; ] ... \
[ \fBelse\fP \fIlist\fP; ] \fBfi\fP
The
.B if
.I list
is executed. If its exit status is zero, the
\fBthen\fP \fIlist\fP is executed. Otherwise, each \fBelif\fP
\fIlist\fP is executed in turn, and if its exit status is zero,
the corresponding \fBthen\fP \fIlist\fP is executed and the
command completes. Otherwise, the \fBelse\fP \fIlist\fP is
executed, if present. The exit status is the exit status of the
last command executed, or zero if no condition tested true.
.TP
\fBwhile\fP \fIlist-1\fP; \fBdo\fP \fIlist-2\fP; \fBdone\fP
.PD 0
.TP
\fBuntil\fP \fIlist-1\fP; \fBdo\fP \fIlist-2\fP; \fBdone\fP
.PD
The \fBwhile\fP command continuously executes the list
\fIlist-2\fP as long as the last command in the list \fIlist-1\fP returns
an exit status of zero. The \fBuntil\fP command is identical
to the \fBwhile\fP command, except that the test is negated:
.I list-2
is executed as long as the last command in
.I list-1
returns a non-zero exit status.
The exit status of the \fBwhile\fP and \fBuntil\fP commands
is the exit status
of the last command executed in \fIlist-2\fP, or zero if
none was executed.
.SS Coprocesses
A \fIcoprocess\fP is a shell command preceded by the \fBcoproc\fP reserved
word.
A coprocess is executed asynchronously in a subshell, as if the command
had been terminated with the \fB&\fP control operator, with a two-way pipe
established between the executing shell and the coprocess.
.PP
The syntax for a coprocess is:
.RS
.PP
\fBcoproc\fP [\fINAME\fP] \fIcommand\fP [\fIredirections\fP]
.RE
.PP
This creates a coprocess named \fINAME\fP.
\fIcommand\fP may be either a simple command or a compound
command (see above).
\fINAME\fP is a shell variable name.
If \fINAME\fP is not supplied, the default name is \fBCOPROC\fP.
.PP
The recommended form to use for a coprocess is
.RS
.PP
\fBcoproc\fP \fINAME\fP { \fIcommand\fP [\fIredirections\fP]; }
.RE
.PP
This form is recommended because simple commands result in the coprocess
always being named \fBCOPROC\fP, and it is simpler to use and more complete
than the other compound commands.
.PP
If \fIcommand\fP is a compound command, \fINAME\fP is optional. The
word following \fBcoproc\fP determines whether that word is interpreted
as a variable name: it is interpreted as \fINAME\fP if it is not a
reserved word that introduces a compound command.
If \fIcommand\fP is a simple command, \fINAME\fP is not allowed; this
is to avoid confusion between \fINAME\fP and the first word of the simple
command.
.PP
When the coprocess is executed, the shell creates an array variable (see
.B Arrays
below) named \fINAME\fP in the context of the executing shell.