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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
|
.\"
.\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
.\" permission to reproduce portions of its copyrighted documentation.
.\" Original documentation from The Open Group can be obtained online at
.\" http://www.opengroup.org/bookstore/.
.\"
.\" The Institute of Electrical and Electronics Engineers and The Open
.\" Group, have given us permission to reprint portions of their
.\" documentation.
.\"
.\" In the following statement, the phrase ``this text'' refers to portions
.\" of the system documentation.
.\"
.\" Portions of this text are reprinted and reproduced in electronic form
.\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
.\" Standard for Information Technology -- Portable Operating System
.\" Interface (POSIX), The Open Group Base Specifications Issue 6,
.\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
.\" Engineers, Inc and The Open Group. In the event of any discrepancy
.\" between these versions and the original IEEE and The Open Group
.\" Standard, the original IEEE and The Open Group Standard is the referee
.\" document. The original Standard can be obtained online at
.\" http://www.opengroup.org/unix/online.html.
.\"
.\" This notice shall appear on any product containing this material.
.\"
.\" The contents of this file are subject to the terms of the
.\" Common Development and Distribution License (the "License").
.\" You may not use this file except in compliance with the License.
.\"
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
.\" or http://www.opensolaris.org/os/licensing.
.\" See the License for the specific language governing permissions
.\" and limitations under the License.
.\"
.\" When distributing Covered Code, include this CDDL HEADER in each
.\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
.\" If applicable, add the following below this CDDL HEADER, with the
.\" fields enclosed by brackets "[]" replaced with your own identifying
.\" information: Portions Copyright [yyyy] [name of copyright owner]
.\"
.\"
.\" Copyright 1989 AT&T
.\" Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved
.\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved.
.\"
.TH SH 1HAS "April 9, 2016"
.SH NAME
sh, jsh \- standard and job control shell and command interpreter
.SH SYNOPSIS
.LP
.nf
\fB/usr/bin/sh\fR [\fB-acefhiknprstuvx\fR] [\fIargument\fR]...
.fi
.LP
.nf
\fB/usr/xpg4/bin/sh\fR [\(+- abCefhikmnoprstuvx]
[\(+- o \fIoption\fR]... [\fB-c\fR \fIstring\fR] [\fIarg\fR]...
.fi
.LP
.nf
\fB/usr/bin/jsh\fR [\fB-acefhiknprstuvx\fR] [\fIargument\fR]...
.fi
.SH DESCRIPTION
.LP
The \fB/usr/bin/sh\fR utility is a command programming language that executes
commands read from a terminal or a file.
.sp
.LP
The \fB/usr/xpg4/bin/sh\fR utility is a standards compliant shell. This utility
provides all the functionality of \fBksh\fR(1), except in cases discussed in
\fBksh\fR(1) where differences in behavior exist.
.sp
.LP
The \fBjsh\fR utility is an interface to the shell that provides all of the
functionality of \fBsh\fR and enables job control (see \fBJob Control\fR
section below).
.sp
.LP
Arguments to the shell are listed in the \fBInvocation\fR section below.
.SS "Definitions"
.LP
A \fIblank\fR is a tab or a space. A \fIname\fR is a sequence of \fBASCII\fR
letters, digits, or underscores, beginning with a letter or an underscore. A
\fIparameter\fR is a name, a digit, or any of the characters \fB*\fR, \fB@\fR,
\fB#\fR, \fB?\fR, \fB\(mi\fR, \fB$\fR, and \fB!\fR.
.SH USAGE
.SS "Commands"
.LP
A \fIsimple-command\fR is a sequence of non-blank \fIword\fRs separated by
\fIblank\fRs. The first \fIword\fR specifies the name of the command to be
executed. Except as specified below, the remaining \fIword\fRs are passed as
arguments to the invoked command. The command name is passed as argument 0 (see
\fBexec\fR(2)). The \fIvalue\fR of a \fIsimple-command\fR is its exit status if
it terminates normally, or (octal) \fB200\fR+\fIstatus\fR if it terminates
abnormally. See \fBsignal.h\fR(3HEAD) for a list of status values.
.sp
.LP
A \fIpipeline\fR is a sequence of one or more \fIcommand\fRs separated by
\fB|\fR. The standard output of each \fIcommand\fR but the last is connected by
a \fBpipe\fR(2) to the standard input of the next \fIcommand\fR. Each
\fIcommand\fR is run as a separate process. The shell waits for the last
\fIcommand\fR to terminate. The exit status of a \fIpipeline\fR is the exit
status of the last command in the \fIpipeline\fR.
.sp
.LP
A \fIlist\fR is a sequence of one or more \fIpipeline\fRs separated by \fB;\fR,
\fB&\fR, \fB&&\fR, or \fB|\||\fR, and optionally terminated by \fB;\fR or
\fB&\fR\&. Of these four symbols, \fB;\fR and \fB&\fR have equal precedence,
which is lower than that of \fB&&\fR and \fB|\||\fR. The symbols \fB&&\fR and
\fB|\||\fR also have equal precedence. A semicolon (\fB;\fR) causes sequential
execution of the preceding \fIpipeline\fR, that is, the shell waits for the
\fIpipeline\fR to finish before executing any commands following the semicolon.
An ampersand (\fB&\fR) causes asynchronous execution of the preceding pipeline,
that is, the shell does \fBnot\fR wait for that pipeline to finish. The symbol
\fB&&\fR (\|\fB|\||\fR) causes the \fIlist\fR following it to be executed only
if the preceding pipeline returns a zero (non-zero) exit status. An arbitrary
number of newlines can appear in a \fIlist\fR, instead of semicolons, to
delimit commands.
.sp
.LP
A \fIcommand\fR is either a \fIsimple-command\fR or one of the following.
Unless otherwise stated, the value returned by a command is that of the last
\fIsimple-command\fR executed in the command.
.sp
.ne 2
.na
\fB\fBfor\fR \fIname\fR [ \fBin\fR \fIword\fR .\|.\|. ] \fBdo\fR \fIlist\fR
\fBdone\fR\fR
.ad
.sp .6
.RS 4n
Each time a \fBfor\fR command is executed, \fIname\fR is set to the next
\fIword\fR taken from the \fBin\fR \fIword\fR list. If \fBin\fR
\fIword\fR .\|.\|. is omitted, then the \fBfor\fR command executes the \fBdo\fR \fIlist\fR
once for each positional parameter that is set (see \fBParameter
Substitution\fR section below). Execution ends when there are no more words in
the list.
.RE
.sp
.ne 2
.na
\fB\fBcase\fR \fIword\fR \fBin\fR [ \fIpattern\fR [ | \fIpattern\fR ] \fB)\fR
\fIlist\fR \fB;\|;\fR ] .\|.\|. \fBesac\fR\fR
.ad
.sp .6
.RS 4n
A \fBcase\fR command executes the \fIlist\fR associated with the first
\fIpattern\fR that matches \fIword\fR. The form of the patterns is the same as
that used for file-name generation (see \fBFile Name Generation\fR section),
except that a slash, a leading dot, or a dot immediately following a slash need
not be matched explicitly.
.RE
.sp
.LP
\fBif\fR \fIlist\fR \fB; then\fR \fIlist\fR \fBelif\fR \fIlist\fR \fB; then\fR
\fIlist\fR \fB;\fR ] .\|.\|. [ \fBelse\fR \fIlist\fR \fB;\fR ] \fBfi\fR
.sp
.LP
The \fIlist\fR following \fBif\fR is executed and, if it returns a zero exit
status, the \fIlist\fR following the first \fBthen\fR is executed. Otherwise,
the \fIlist\fR following \fBelif\fR is executed and, if its value is zero, the
\fIlist\fR following the next \fBthen\fR is executed. Failing that, the
\fBelse\fR \fIlist\fR is executed. If no \fBelse\fR \fIlist\fR or \fBthen\fR
\fIlist\fR is executed, then the \fBif\fR command returns a zero exit status.
.sp
.ne 2
.na
\fB\fBwhile\fR \fIlist\fR \fBdo\fR \fIlist\fR \fBdone\fR\fR
.ad
.RS 27n
A \fBwhile\fR command repeatedly executes the \fBwhile\fR \fIlist\fR and, if
the exit status of the last command in the list is zero, executes the \fBdo\fR
\fIlist\fR; otherwise the loop terminates. If no commands in the \fBdo\fR
\fIlist\fR are executed, then the \fBwhile\fR command returns a zero exit
status; \fBuntil\fR can be used in place of \fBwhile\fR to negate the loop
termination test.
.RE
.sp
.ne 2
.na
\fB\fB(\fR\fIlist\fR\fB)\fR\fR
.ad
.RS 27n
Execute \fIlist\fR in a sub-shell.
.RE
.sp
.ne 2
.na
\fB\fB{\fR \fIlist\fR\fB;}\fR\fR
.ad
.RS 27n
\fIlist\fR is executed in the current (that is, parent) shell. The \fB{\fR must
be followed by a space.
.RE
.sp
.ne 2
.na
\fB\fIname\fR \fB(\|) {\fR \fIlist\fR\fB;}\fR\fR
.ad
.RS 27n
Define a function which is referenced by \fIname\fR. The body of the function
is the \fIlist\fR of commands between \fB{\fR and \fB}\fR. The \fB{\fR must be
followed by a space. Execution of functions is described below (see
\fBExecution\fR section). The \fB{\fR and \fB}\fR are unnecessary if the body
of the function is a \fIcommand\fR as defined above, under \fBCommands\fR.
.RE
.sp
.LP
The following words are only recognized as the first word of a command and when
not quoted:
.sp
.LP
\fBif then else elif fi case esac for while until do done { }\fR
.SS "Comments Lines"
.LP
A word beginning with \fB#\fR causes that word and all the following characters
up to a newline to be ignored.
.SS "Command Substitution"
.LP
The shell reads commands from the string between two grave accents (\fB``\fR)
and the standard output from these commands can be used as all or part of a
word. Trailing newlines from the standard output are removed.
.sp
.LP
No interpretation is done on the string before the string is read, except to
remove backslashes (\fB\e\fR) used to escape other characters. Backslashes can
be used to escape a grave accent (\fB`\fR) or another backslash (\fB\e\fR) and
are removed before the command string is read. Escaping grave accents allows
nested command substitution. If the command substitution lies within a pair of
double quotes (\fB" .\|.\|.\|` .\|.\|.\|` .\|.\|.\| "\fR), a backslash used to
escape a double quote (\fB\e"\fR) is removed. Otherwise, it is left intact.
.sp
.LP
If a backslash is used to escape a newline character (\fB\enewline\fR), both
the backslash and the newline are removed (see the later section on
\fBQuoting\fR). In addition, backslashes used to escape dollar signs
(\fB\e$\fR) are removed. Since no parameter substitution is done on the command
string before it is read, inserting a backslash to escape a dollar sign has no
effect. Backslashes that precede characters other than \fB\e\fR, \fB`\fR,
\fB"\fR, \fBnewline\fR, and \fB$\fR are left intact when the command string is
read.
.SS "Parameter Substitution"
.LP
The character \fB$\fR is used to introduce substitutable \fIparameter\fRs.
There are two types of parameters, positional and keyword. If \fIparameter\fR
is a digit, it is a positional parameter. Positional parameters can be assigned
values by \fBset\fR. Keyword parameters (also known as variables) can be
assigned values by writing:
.sp
.LP
\fIname\fR\fB=\fR\fIvalue\fR [ \fIname\fR\fB=\fR\fIvalue\fR ] .\|.\|.
.sp
.LP
Pattern-matching is not performed on \fIvalue\fR. There cannot be a function
and a variable with the same \fIname\fR.
.sp
.ne 2
.na
\fB\fB${\fR\fIparameter\fR\fB}\fR\fR
.ad
.RS 25n
The value, if any, of the parameter is substituted. The braces are required
only when \fIparameter\fR is followed by a letter, digit, or underscore that is
not to be interpreted as part of its name. If \fIparameter\fR is \fB*\fR or
\fB@\fR, all the positional parameters, starting with \fB$1\fR, are substituted
(separated by spaces). Parameter \fB$0\fR is set from argument zero when the
shell is invoked.
.RE
.sp
.ne 2
.na
\fB\fB${\fR\fIparameter\fR\fB:\(mi\fR\fIword\fR\fB}\fR\fR
.ad
.RS 25n
Use Default Values. If \fIparameter\fR is unset or null, the expansion of
\fIword\fR is substituted; otherwise, the value of \fIparameter\fR is
substituted.
.RE
.sp
.ne 2
.na
\fB\fB${\fR\fIparameter\fR\fB:=\fR\fIword\fR\fB}\fR\fR
.ad
.RS 25n
Assign Default Values. If \fIparameter\fR is unset or null, the expansion of
\fIword\fR is assigned to \fIparameter\fR. In all cases, the final value of
\fIparameter\fR is substituted. Only variables, not positional parameters or
special parameters, can be assigned in this way.
.RE
.sp
.ne 2
.na
\fB\fB${\fR\fIparameter\fR\fB:?\fR\fIword\fR\fB}\fR\fR
.ad
.RS 25n
If \fIparameter\fR is set and is non-null, substitute its value; otherwise,
print \fIword\fR and exit from the shell. If \fIword\fR is omitted, the message
"parameter null or not set" is printed.
.RE
.sp
.ne 2
.na
\fB\fB${\fR\fIparameter\fR\fB:+\fR\fIword\fR\fB}\fR\fR
.ad
.RS 25n
If \fIparameter\fR is set and is non-null, substitute \fIword\fR; otherwise
substitute nothing.
.RE
.sp
.LP
In the above, \fIword\fR is not evaluated unless it is to be used as the
substituted string, so that, in the following example, \fBpwd\fR is executed
only if \fBd\fR is not set or is null:
.sp
.in +2
.nf
\fBecho ${d:\(mi`pwd`}\fR
.fi
.in -2
.sp
.sp
.LP
If the colon (\fB:\fR) is omitted from the above expressions, the shell only
checks whether \fIparameter\fR is set or not.
.sp
.LP
The following parameters are automatically set by the shell.
.sp
.ne 2
.na
\fB\fB#\fR\fR
.ad
.RS 8n
The number of positional parameters in decimal.
.RE
.sp
.ne 2
.na
\fB\fB\(mi\fR\fR
.ad
.RS 8n
Flags supplied to the shell on invocation or by the \fBset\fR command.
.RE
.sp
.ne 2
.na
\fB\fB?\fR\fR
.ad
.RS 8n
The decimal value returned by the last synchronously executed command.
.RE
.sp
.ne 2
.na
\fB\fB$\fR\fR
.ad
.RS 8n
The process number of this shell.
.RE
.sp
.ne 2
.na
\fB\fB!\fR\fR
.ad
.RS 8n
The process number of the last background command invoked.
.RE
.sp
.LP
The following parameters are used by the shell. The parameters in this section
are also referred to as environment variables.
.sp
.ne 2
.na
\fB\fBHOME\fR\fR
.ad
.RS 13n
The default argument (home directory) for the \fBcd\fR command, set to the
user's login directory by \fBlogin\fR(1) from the password file (see
\fBpasswd\fR(5)).
.RE
.sp
.ne 2
.na
\fB\fBPATH\fR\fR
.ad
.RS 13n
The search path for commands (see \fBExecution\fR section below).
.RE
.sp
.ne 2
.na
\fB\fBCDPATH\fR\fR
.ad
.RS 13n
The search path for the \fBcd\fR command.
.RE
.sp
.ne 2
.na
\fB\fBMAIL\fR\fR
.ad
.RS 13n
If this parameter is set to the name of a mail file \fIand\fR the
\fBMAILPATH\fR parameter is not set, the shell informs the user of the arrival
of mail in the specified file.
.RE
.sp
.ne 2
.na
\fB\fBMAILCHECK\fR\fR
.ad
.RS 13n
This parameter specifies how often (in seconds) the shell checks for the
arrival of mail in the files specified by the \fBMAILPATH\fR or \fBMAIL\fR
parameters. The default value is \fB600\fR seconds (10 minutes). If set to 0,
the shell checks before each prompt.
.RE
.sp
.ne 2
.na
\fB\fBMAILPATH\fR\fR
.ad
.RS 13n
A colon-separated list of file names. If this parameter is set, the shell
informs the user of the arrival of mail in any of the specified files. Each
file name can be followed by % and a message that is e printed when the
modification time changes. The default message is, \fByou have mail\fR.
.RE
.sp
.ne 2
.na
\fB\fBPS1\fR\fR
.ad
.RS 13n
Primary prompt string, by default " $ \|".
.RE
.sp
.ne 2
.na
\fB\fBPS2\fR\fR
.ad
.RS 13n
Secondary prompt string, by default " > \|".
.RE
.sp
.ne 2
.na
\fB\fBIFS\fR\fR
.ad
.RS 13n
Internal field separators, normally \fBspace\fR, \fBtab\fR, and \fBnewline\fR
(see \fBBlank Interpretation\fR section).
.RE
.sp
.ne 2
.na
\fB\fBSHACCT\fR\fR
.ad
.RS 13n
If this parameter is set to the name of a file writable by the user, the shell
writes an accounting record in the file for each shell procedure executed.
.RE
.sp
.ne 2
.na
\fB\fBSHELL\fR\fR
.ad
.RS 13n
When the shell is invoked, it scans the environment (see \fBEnvironment\fR
section below) for this name.
.RE
.sp
.LP
See \fBenviron\fR(7) for descriptions of the following environment variables
that affect the execution of \fBsh\fR: \fBLC_CTYPE\fR and \fBLC_MESSAGES\fR.
.sp
.LP
The shell gives default values to \fBPATH\fR, \fBPS1\fR, \fBPS2\fR,
\fBMAILCHECK\fR, and \fBIFS\fR. Default values for \fBHOME\fR and \fBMAIL\fR
are set by \fBlogin\fR(1).
.SS "Blank Interpretation"
.LP
After parameter and command substitution, the results of substitution are
scanned for internal field separator characters (those found in \fBIFS\fR) and
split into distinct arguments where such characters are found. Explicit null
arguments (\fB""\fR or \fB\&''\fR) are retained. Implicit null arguments (those
resulting from \fIparameter\fRs that have no values) are removed.
.SS "Input/Output Redirection"
.LP
A command's input and output can be redirected using a special notation
interpreted by the shell. The following can appear anywhere in a
\fIsimple-command\fR or can precede or follow a \fIcommand\fR and are \fBnot\fR
passed on as arguments to the invoked command. \fBNote:\fR Parameter and
command substitution occurs before \fIword\fR or \fIdigit\fR is used.
.sp
.ne 2
.na
\fB\fB<\fR\fIword\fR\fR
.ad
.RS 16n
Use file \fIword\fR as standard input (file descriptor 0).
.RE
.sp
.ne 2
.na
\fB\fB>\fR\fIword\fR\fR
.ad
.RS 16n
Use file \fIword\fR as standard output (file descriptor 1). If the file does
not exist, it is created; otherwise, it is truncated to zero length.
.RE
.sp
.ne 2
.na
\fB\fB>>\fR\fIword\fR\fR
.ad
.RS 16n
Use file \fIword\fR as standard output. If the file exists, output is appended
to it by first seeking to the \fBEOF\fR. Otherwise, the file is created.
.RE
.sp
.ne 2
.na
\fB\fB<\|>\fR\fIword\fR\fR
.ad
.RS 16n
Open file \fIword\fR for reading and writing as standard input.
.RE
.sp
.ne 2
.na
\fB\fB<<\fR[\fB\(mi\fR]\fIword\fR\fR
.ad
.RS 16n
After parameter and command substitution is done on \fIword\fR, the shell input
is read up to the first line that literally matches the resulting \fIword\fR,
or to an \fBEOF\fR. If, however, the hyphen (\fB\(mi\fR) is appended to
\fB<<\fR:
.RS +4
.TP
1.
leading tabs are stripped from \fIword\fR before the shell input is read
(but after parameter and command substitution is done on \fIword\fR);
.RE
.RS +4
.TP
2.
leading tabs are stripped from the shell input as it is read and before each
line is compared with \fIword\fR; and
.RE
.RS +4
.TP
3.
shell input is read up to the first line that literally matches the
resulting \fIword\fR, or to an \fBEOF\fR.
.RE
If any character of \fIword\fR is quoted (see \fBQuoting\fR section later), no
additional processing is done to the shell input. If no characters of
\fIword\fR are quoted:
.RS +4
.TP
1.
parameter and command substitution occurs;
.RE
.RS +4
.TP
2.
(escaped) \fB\enewline\fRs are removed; and
.RE
.RS +4
.TP
3.
\fB\e\fR must be used to quote the characters \fB\e\fR, \fB$\fR, and
\fB`\fR.
.RE
The resulting document becomes the standard input.
.RE
.sp
.ne 2
.na
\fB\fB<&\fR\fIdigit\fR\fR
.ad
.RS 16n
Use the file associated with file descriptor \fIdigit\fR as standard input.
Similarly for the standard output using \fB>&\fR\fIdigit\fR.
.RE
.sp
.ne 2
.na
\fB\fB<&\(mi\fR\fR
.ad
.RS 16n
The standard input is closed. Similarly for the standard output using
\fB>&\(mi\fR.
.RE
.sp
.LP
If any of the above is preceded by a digit, the file descriptor which is
associated with the file is that specified by the digit (instead of the default
\fB0\fR or \fB1\fR). For example:
.sp
.in +2
.nf
\fB\&... 2>&1\fR
.fi
.in -2
.sp
.sp
.LP
associates file descriptor 2 with the file currently associated with file
descriptor 1.
.sp
.LP
The order in which redirections are specified is significant. The shell
evaluates redirections left-to-right. For example:
.sp
.in +2
.nf
\fB\&... 1>\fIxxx\fR 2>&1\fR
.fi
.in -2
.sp
.sp
.LP
first associates file descriptor 1 with file \fIxxx\fR. It associates file
descriptor 2 with the file associated with file descriptor 1 (that is,
\fIxxx\fR). If the order of redirections were reversed, file descriptor 2 would
be associated with the terminal (assuming file descriptor 1 had been) and file
descriptor 1 would be associated with file \fIxxx\fR.
.sp
.LP
Using the terminology introduced on the first page, under \fBCommands\fR, if a
\fIcommand\fR is composed of several \fIsimple commands\fR, redirection is
evaluated for the entire \fIcommand\fR before it is evaluated for each
\fIsimple command\fR. That is, the shell evaluates redirection for the entire
\fIlist\fR, then each \fIpipeline\fR within the \fIlist\fR, then each
\fIcommand\fR within each \fIpipeline\fR, then each \fIlist\fR within each
\fIcommand\fR.
.sp
.LP
If a command is followed by \fB&\fR, the default standard input for the command
is the empty file, \fB/dev/null\fR. Otherwise, the environment for the
execution of a command contains the file descriptors of the invoking shell as
modified by input/output specifications.
.SS "File Name Generation"
.LP
Before a command is executed, each command \fIword\fR is scanned for the
characters \fB*\fR, \fB?\fR, and \fB[\fR. If one of these characters appears
the word is regarded as a \fIpattern\fR. The word is replaced with
alphabetically sorted file names that match the pattern. If no file name is
found that matches the pattern, the word is left unchanged. The character
\fB\&.\fR at the start of a file name or immediately following a \fB/\fR, as
well as the character \fB/\fR itself, must be matched explicitly.
.sp
.ne 2
.na
\fB\fB*\fR\fR
.ad
.RS 13n
Matches any string, including the null string.
.RE
.sp
.ne 2
.na
\fB\fB?\fR\fR
.ad
.RS 13n
Matches any single character.
.RE
.sp
.ne 2
.na
\fB\fB[\fR.\|.\|.\fB]\fR\fR
.ad
.RS 13n
Matches any one of the enclosed characters. A pair of characters separated by
\fB\(mi\fR matches any character lexically between the pair, inclusive. If the
first character following the opening \fB[\fR is a \fB!\fR, any character not
enclosed is matched.
.RE
.sp
.LP
Notice that all quoted characters (see below) must be matched explicitly in a
filename.
.SS "Quoting"
.LP
The following characters have a special meaning to the shell and cause
termination of a word unless quoted:
.sp
.LP
\fB; & ( ) | ^ < > newline space tab\fR
.sp
.LP
A character can be \fIquoted\fR (that is, made to stand for itself) by
preceding it with a backslash (\fB\e\fR) or inserting it between a pair of
quote marks (\fB\|'\|'\fR or \fB""\fR). During processing, the shell can quote
certain characters to prevent them from taking on a special meaning.
Backslashes used to quote a single character are removed from the word before
the command is executed. The pair \fB\enewline\fR is removed from a word before
command and parameter substitution.
.sp
.LP
All characters enclosed between a pair of single quote marks (\fB\|'\|'\fR),
except a single quote, are quoted by the shell. Backslash has no special
meaning inside a pair of single quotes. A single quote can be quoted inside a
pair of double quote marks (for example, \fB"\|'"\fR), but a single quote can
not be quoted inside a pair of single quotes.
.sp
.LP
Inside a pair of double quote marks (\fB""\fR), parameter and command
substitution occurs and the shell quotes the results to avoid blank
interpretation and file name generation. If \fB$*\fR is within a pair of double
quotes, the positional parameters are substituted and quoted, separated by
quoted spaces (\fB"$1 \|$2\fR \|.\|.\|.\fB"\fR). However, if \fB$@\fR is within
a pair of double quotes, the positional parameters are substituted and quoted,
separated by unquoted spaces (\fB"$1"\|"$2"\fR \| .\|.\|. ). \fB\e\fR quotes
the characters \fB\e\fR, \fB`\fR, \fB,\fR (comma), and \fB$\fR. The pair
\fB\enewline\fR is removed before parameter and command substitution. If a
backslash precedes characters other than \fB\e\fR, \fB`\fR, \fB,\fR (comma),
\fB$\fR, and newline, then the backslash itself is quoted by the shell.
.SS "Prompting"
.LP
When used interactively, the shell prompts with the value of \fBPS1\fR before
reading a command. If at any time a newline is typed and further input is
needed to complete a command, the secondary prompt (that is, the value of
\fBPS2\fR) is issued.
.SS "Environment"
.LP
The \fIenvironment\fR (see \fBenviron\fR(7)) is a list of name-value pairs that
is passed to an executed program in the same way as a normal argument list. The
shell interacts with the environment in several ways. On invocation, the shell
scans the environment and creates a parameter for each name found, giving it
the corresponding value. If the user modifies the value of any of these
parameters or creates new parameters, none of these affects the environment
unless the \fBexport\fR command is used to bind the shell's parameter to the
environment (see also \fBset\fR \fB-a\fR). A parameter can be removed from the
environment with the \fBunset\fR command. The environment seen by any executed
command is thus composed of any unmodified name-value pairs originally
inherited by the shell, minus any pairs removed by \fBunset\fR, plus any
modifications or additions, all of which must be noted in \fBexport\fR
commands.
.sp
.LP
The environment for any \fIsimple-command\fR can be augmented by prefixing it
with one or more assignments to parameters. Thus:
.sp
.in +2
.nf
\fBTERM=450 \fIcommand\fR\fR
.fi
.in -2
.sp
.sp
.LP
and
.sp
.in +2
.nf
\fB(export TERM; TERM=450; \fIcommand\fR\fR
.fi
.in -2
.sp
.sp
.LP
are equivalent as far as the execution of \fIcommand\fR is concerned if
\fIcommand\fR is not a Special Command. If \fIcommand\fR is a Special Command,
then
.sp
.in +2
.nf
\fBTERM=450 \fIcommand\fR\fR
.fi
.in -2
.sp
.sp
.LP
modifies the \fBTERM\fR variable in the current shell.
.sp
.LP
If the \fB-k\fR flag is set, \fIall\fR keyword arguments are placed in the
environment, even if they occur after the command name. The following example
first prints \fBa=b c\fR and \fBc\fR:
.sp
.in +2
.nf
\fBecho a=b c
a=b c
set \(mik
echo a=b c
c\fR
.fi
.in -2
.sp
.SS "Signals"
.LP
The \fBINTERRUPT\fR and \fBQUIT\fR signals for an invoked command are ignored
if the command is followed by \fB&\fR\&. Otherwise, signals have the values
inherited by the shell from its parent, with the exception of signal 11 (but
see also the \fBtrap\fR command below).
.SS "Execution"
.LP
Each time a command is executed, the command substitution, parameter
substitution, blank interpretation, input/output redirection, and filename
generation listed above are carried out. If the command name matches the name
of a defined function, the function is executed in the shell process (note how
this differs from the execution of shell script files, which require a
sub-shell for invocation). If the command name does not match the name of a
defined function, but matches one of the \fBSpecial Commands\fR listed below,
it is executed in the shell process.
.sp
.LP
The positional parameters \fB$1\fR, \fB$2\fR, .\|.\|. are set to the arguments
of the function. If the command name matches neither a \fBSpecial Command\fR
nor the name of a defined function, a new process is created and an attempt is
made to execute the command via \fBexec\fR(2).
.sp
.LP
The shell parameter \fBPATH\fR defines the search path for the directory
containing the command. Alternative directory names are separated by a colon
(\fB:\fR). The default path is \fB/usr/bin\fR. The current directory is
specified by a null path name, which can appear immediately after the equal
sign, between two colon delimiters anywhere in the path list, or at the end of
the path list. If the command name contains a \fB/\fR the search path is not
used. Otherwise, each directory in the path is searched for an executable file.
If the file has execute permission but is not an \fBa.out\fR file, it is
assumed to be a file containing shell commands. A sub-shell is spawned to read
it. A parenthesized command is also executed in a sub-shell.
.sp
.LP
The location in the search path where a command was found is remembered by the
shell (to help avoid unnecessary \fIexec\fRs later). If the command was found
in a relative directory, its location must be re-determined whenever the
current directory changes. The shell forgets all remembered locations whenever
the \fBPATH\fR variable is changed or the \fBhash\fR \fB-r\fR command is
executed (see below).
.SS "Special Commands"
.LP
Input/output redirection is now permitted for these commands. File descriptor 1
is the default output location. When Job Control is enabled, additional
\fBSpecial Commands\fR are added to the shell's environment (see \fBJob
Control\fR section below).
.sp
.ne 2
.na
\fB\fB:\fR\fR
.ad
.sp .6
.RS 4n
No effect; the command does nothing. A zero exit code is returned.
.RE
.sp
.ne 2
.na
\fB\fB\&.\|\fR \fIfilename\fR\fR
.ad
.sp .6
.RS 4n
Read and execute commands from \fIfilename\fR and return. The search path
specified by \fBPATH\fR is used to find the directory containing
\fIfilename\fR.
.RE
.sp
.ne 2
.na
\fB\fBbg\fR [\fB%\fR\fIjobid .\|.\|.\fR]\fR
.ad
.sp .6
.RS 4n
When Job Control is enabled, the \fBbg\fR command is added to the user's
environment to manipulate jobs. Resumes the execution of a stopped job in the
background. If \fB%\fR\fIjobid\fR is omitted the current job is assumed. (See
\fBJob Control\fR section below for more detail.)
.RE
.sp
.ne 2
.na
\fB\fBbreak\fR [ \fIn\fR ]\fR
.ad
.sp .6
.RS 4n
Exit from the enclosing \fBfor\fR or \fBwhile\fR loop, if any. If \fIn\fR is
specified, break \fIn\fR levels.
.RE
.sp
.ne 2
.na
\fB\fBcd\fR [ \fIargument\fR ]\fR
.ad
.sp .6
.RS 4n
Change the current directory to \fIargument\fR. The shell parameter \fBHOME\fR
is the default \fIargument\fR. The shell parameter \fBCDPATH\fR defines the
search path for the directory containing \fIargument\fR. Alternative directory
names are separated by a colon (\fB:\fR). The default path is \fB<null>\fR
(specifying the current directory). \fBNote:\fR The current directory is
specified by a null path name, which can appear immediately after the equal
sign or between the colon delimiters anywhere else in the path list. If
\fIargument\fR begins with a \fB/\fR the search path is not used. Otherwise,
each directory in the path is searched for \fIargument\fR.
.RE
.sp
.ne 2
.na
\fB\fBchdir\fR [ \fIdir\fR ]\fR
.ad
.sp .6
.RS 4n
\fBchdir\fR changes the shell's working directory to directory \fIdir\fR. If no
argument is given, change to the home directory of the user. If \fIdir\fR is a
relative pathname not found in the current directory, check for it in those
directories listed in the \fBCDPATH\fR variable. If \fIdir\fR is the name of a
shell variable whose value starts with a \fB/\fR, change to the directory named
by that value.
.RE
.sp
.ne 2
.na
\fB\fBcontinue\fR [ \fIn\fR ]\fR
.ad
.sp .6
.RS 4n
Resume the next iteration of the enclosing \fBfor\fR or \fBwhile\fR loop. If
\fIn\fR is specified, resume at the \fIn\fR-th enclosing loop.
.RE
.sp
.ne 2
.na
\fB\fBecho\fR [ \fIarguments\fR .\|.\|. ]\fR
.ad
.sp .6
.RS 4n
The words in \fIarguments\fR are written to the shell's standard output,
separated by space characters. See \fBecho\fR(1) for fuller usage and
description.
.RE
.sp
.ne 2
.na
\fB\fBeval\fR [ \fIargument\fR .\|.\|. ]\fR
.ad
.sp .6
.RS 4n
The arguments are read as input to the shell and the resulting command(s)
executed.
.RE
.sp
.ne 2
.na
\fB\fBexec\fR [ \fIargument\fR .\|.\|. ]\fR
.ad
.sp .6
.RS 4n
The command specified by the arguments is executed in place of this shell
without creating a new process. Input/output arguments can appear and, if no
other arguments are given, cause the shell input/output to be modified.
.RE
.sp
.ne 2
.na
\fB\fBexit\fR [ \fIn\fR ]\fR
.ad
.sp .6
.RS 4n
Causes the calling shell or shell script to exit with the exit status specified
by \fIn\fR. If \fIn\fR is omitted the exit status is that of the last command
executed (an \fBEOF\fR also causes the shell to exit.)
.RE
.sp
.ne 2
.na
\fB\fBexport\fR [ \fIname\fR .\|.\|. ]\fR
.ad
.sp .6
.RS 4n
The given \fIname\fRs are marked for automatic export to the \fIenvironment\fR
of subsequently executed commands. If no arguments are given, variable names
that have been marked for export during the current shell's execution are
listed. (Variable names exported from a parent shell are listed only if they
have been exported again during the current shell's execution.) Function names
are \fBnot\fR exported.
.RE
.sp
.ne 2
.na
\fB\fBfg\fR [\fB%\fR\fIjobid .\|.\|.\fR]\fR
.ad
.sp .6
.RS 4n
When Job Control is enabled, the \fBfg\fR command is added to the user's
environment to manipulate jobs. This command resumes the execution of a stopped
job in the foreground and also moves an executing background job into the
foreground. If \fB%\fR\fIjobid\fR is omitted, the current job is assumed. (See
\fBJob Control\fR section below for more detail.)
.RE
.sp
.ne 2
.na
\fB\fBgetopts\fR\fR
.ad
.sp .6
.RS 4n
Use in shell scripts to support command syntax standards (see \fBIntro\fR(1)).
This command parses positional parameters and checks for legal options. See
\fBgetoptcvt\fR(1) for usage and description.
.RE
.sp
.ne 2
.na
\fB\fBhash\fR [ \fB-r\fR ] [ \fIname\fR .\|.\|. ]\fR
.ad
.sp .6
.RS 4n
For each \fIname\fR, the location in the search path of the command specified
by \fIname\fR is determined and remembered by the shell. The \fB-r\fR option
causes the shell to forget all remembered locations. If no arguments are given,
information about remembered commands is presented. \fIHits\fR is the number of
times a command has been invoked by the shell process. \fICost\fR is a measure
of the work required to locate a command in the search path. If a command is
found in a "relative" directory in the search path, after changing to that
directory, the stored location of that command is recalculated. Commands for
which this are done are indicated by an asterisk (\fB*\fR) adjacent to the
\fIhits\fR information. \fICost\fR is incremented when the recalculation is
done.
.RE
.sp
.ne 2
.na
\fB\fBjobs\fR [\fB\fR\fB-p\fR\fB|\fR\fB-l\fR] [\fB%\fR\fIjobid ...\fR]\fR
.ad
.br
.na
\fB\fBjobs\fR \fB-x\fR \fIcommand\fR [\fIarguments\fR]\fR
.ad
.sp .6
.RS 4n
Reports all jobs that are stopped or executing in the background. If
\fB%\fR\fIjobid\fR is omitted, all jobs that are stopped or running in the
background are reported. (See \fBJob Control\fR section below for more detail.)
.RE
.sp
.ne 2
.na
\fB\fBkill\fR [ \fB-\fR\fIsig\fR ] \fB%\fR\fIjob\fR .\|.\|.\fR
.ad
.br
.na
\fB\fBkill\fR \fB-l\fR\fR
.ad
.sp .6
.RS 4n
Sends either the \fBTERM\fR (terminate) signal or the specified signal to the
specified jobs or processes. Signals are either given by number or by names (as
given in \fBsignal.h\fR(3HEAD) stripped of the prefix "SIG" with the exception
that \fBSIGCHD\fR is named \fBCHLD\fR). If the signal being sent is \fBTERM\fR
(terminate) or \fBHUP\fR (hangup), then the job or process is sent a \fBCONT\fR
(continue) signal if it is stopped. The argument \fIjob\fR can be the process
id of a process that is not a member of one of the active jobs. See \fBJob
Control\fR section below for a description of the format of \fIjob\fR. In the
second form, \fBkill\fR \fB-l\fR, the signal numbers and names are listed. (See
\fBkill\fR(1)).
.RE
.sp
.ne 2
.na
\fB\fBlogin\fR [ \fIargument\fR .\|.\|. ]\fR
.ad
.sp .6
.RS 4n
Equivalent to `\fBexec\fR \fBlogin\fR \fIargument\fR.\|.\|.\|.' See
\fBlogin\fR(1) for usage and description.
.RE
.sp
.ne 2
.na
\fB\fBnewgrp\fR [ \fIargument\fR ]\fR
.ad
.sp .6
.RS 4n
Equivalent to \fBexec\fR \fBnewgrp\fR \fIargument\fR. See \fBnewgrp\fR(1) for
usage and description.
.RE
.sp
.ne 2
.na
\fB\fBpwd\fR\fR
.ad
.sp .6
.RS 4n
Print the current working directory. See \fBpwd\fR(1) for usage and
description.
.RE
.sp
.ne 2
.na
\fB\fBread\fR \fIname\fR .\|.\|.\fR
.ad
.sp .6
.RS 4n
One line is read from the standard input and, using the internal field
separator, \fBIFS\fR (normally space or tab), to delimit word boundaries, the
first word is assigned to the first \fIname\fR, the second word to the second
\fIname\fR, and so forth, with leftover words assigned to the last \fIname\fR.
Lines can be continued using \fB\enewline\fR\&. Characters other than
\fBnewline\fR can be quoted by preceding them with a backslash. These
backslashes are removed before words are assigned to \fInames\fR, and no
interpretation is done on the character that follows the backslash. The return
code is \fB0\fR, unless an \fBEOF\fR is encountered.
.RE
.sp
.ne 2
.na
\fB\fBreadonly\fR [ \fIname\fR .\|.\|. ]\fR
.ad
.sp .6
.RS 4n
The given \fIname\fRs are marked \fBreadonly\fR and the values of these
\fIname\fRs can not be changed by subsequent assignment. If no arguments are
given, a list of all \fBreadonly\fR names is printed.
.RE
.sp
.ne 2
.na
\fB\fBreturn\fR [ \fIn\fR ]\fR
.ad
.sp .6
.RS 4n
Causes a function to exit with the return value specified by \fIn\fR. If
\fIn\fR is omitted, the return status is that of the last command executed.
.RE
.sp
.ne 2
.na
\fB\fBset\fR [ \fB-aefhkntuvx\fR [ \fIargument\fR .\|.\|. ] ]\fR
.ad
.sp .6
.RS 4n
.sp
.ne 2
.na
\fB\fB-a\fR\fR
.ad
.RS 6n
Mark variables which are modified or created for export.
.RE
.sp
.ne 2
.na
\fB\fB-e\fR\fR
.ad
.RS 6n
Exit immediately if a command exits with a non-zero exit status.
.RE
.sp
.ne 2
.na
\fB\fB-f\fR\fR
.ad
.RS 6n
Disable file name generation.
.RE
.sp
.ne 2
.na
\fB\fB-h\fR\fR
.ad
.RS 6n
Locate and remember function commands as functions are defined (function
commands are normally located when the function is executed).
.RE
.sp
.ne 2
.na
\fB\fB-k\fR\fR
.ad
.RS 6n
All keyword arguments are placed in the environment for a command, not just
those that precede the command name.
.RE
.sp
.ne 2
.na
\fB\fB-n\fR\fR
.ad
.RS 6n
Read commands but do not execute them.
.RE
.sp
.ne 2
.na
\fB\fB-t\fR\fR
.ad
.RS 6n
Exit after reading and executing one command.
.RE
.sp
.ne 2
.na
\fB\fB-u\fR\fR
.ad
.RS 6n
Treat unset variables as an error when substituting.
.RE
.sp
.ne 2
.na
\fB\fB-v\fR\fR
.ad
.RS 6n
Print shell input lines as they are read.
.RE
.sp
.ne 2
.na
\fB\fB-x\fR\fR
.ad
.RS 6n
Print commands and their arguments as they are executed.
.RE
.sp
.ne 2
.na
\fB\fB-\fR\fR
.ad
.RS 6n
Do not change any of the flags; useful in setting \fB$1\fR to \fB\(mi\fR\&.
.RE
Using \fB+\fR rather than \fB\(mi\fR causes these flags to be turned off. These
flags can also be used upon invocation of the shell. The current set of flags
can be found in \fB$\(mi\fR. The remaining arguments are positional parameters
and are assigned, in order, to \fB$1\fR, \fB$2\fR, .\|.\|. If no arguments are
given, the values of all names are printed.
.RE
.sp
.ne 2
.na
\fB\fBshift\fR [ \fIn\fR ]\fR
.ad
.sp .6
.RS 4n
The positional parameters from \fB$\fR\fIn\fR\fB+1\fR .\|.\|. are renamed
\fB$1\fR .\|.\|. . If \fIn\fR is not given, it is assumed to be 1.
.RE
.sp
.ne 2
.na
\fB\fBstop\fR \fIpid .\|.\|.\fR\fR
.ad
.sp .6
.RS 4n
Halt execution of the process number \fIpid\fR. (see \fBps\fR(1)).
.RE
.sp
.ne 2
.na
\fB\fBsuspend\fR\fR
.ad
.sp .6
.RS 4n
Stops the execution of the current shell (but not if it is the login shell).
.RE
.sp
.ne 2
.na
\fB\fBtest\fR\fR
.ad
.sp .6
.RS 4n
Evaluate conditional expressions. See \fBtest\fR(1) for usage and description.
.RE
.sp
.ne 2
.na
\fB\fBtimes\fR\fR
.ad
.sp .6
.RS 4n
Print the accumulated user and system times for processes run from the shell.
.RE
.sp
.ne 2
.na
\fB\fBtrap\fR [ \fIargument\fR \fIn\fR [ \fIn2\fR .\|.\|. ]]\fR
.ad
.sp .6
.RS 4n
The command \fIargument\fR is to be read and executed when the shell receives
numeric or symbolic signal(s) (\fIn\fR). (\fBNote:\fR \fIargument\fR is scanned
once when the trap is set and once when the trap is taken.) Trap commands are
executed in order of signal number or corresponding symbolic names. Any attempt
to set a trap on a signal that was ignored on entry to the current shell is
ineffective. An attempt to trap on signal 11 (memory fault) produces an error.
If \fIargument\fR is absent, all trap(s) \fIn\fR are reset to their original
values. If \fIargument\fR is the null string, this signal is ignored by the
shell and by the commands it invokes. If \fIn\fR is 0, the command
\fIargument\fR is executed on exit from the shell. The \fBtrap\fR command with
no arguments prints a list of commands associated with each signal number.
.RE
.sp
.ne 2
.na
\fB\fBtype\fR [ \fIname\fR .\|.\|. ]\fR
.ad
.sp .6
.RS 4n
For each \fIname\fR, indicate how it would be interpreted if used as a command
name.
.RE
.sp
.ne 2
.na
\fB\fBulimit\fR [ [\fB-HS\fR] [\fB-a\fR | \fB-cdfnstv\fR] ]\fR
.ad
.br
.na
\fB\fBulimit\fR [ [\fB-HS\fR] [\fB-c\fR | \fB-d\fR | \fB-f\fR | \fB-n\fR |
\fB-s\fR | \fB-t\fR | \fB-v\fR] ] \fBlimit\fR\fR
.ad
.sp .6
.RS 4n
\fBulimit\fR prints or sets hard or soft resource limits. These limits are
described in \fBgetrlimit\fR(2).
.sp
If \fIlimit\fR is not present, \fBulimit\fR prints the specified limits. Any
number of limits can be printed at one time. The \fB-a\fR option prints all
limits.
.sp
If \fIlimit\fR is present, \fBulimit\fR sets the specified limit to
\fIlimit\fR. The string \fBunlimited\fR requests that the current limit, if
any, be removed. Any user can set a soft limit to any value less than or equal
to the hard limit. Any user can lower a hard limit. Only a user with
appropriate privileges can raise or remove a hard limit. See
\fBgetrlimit\fR(2).
.sp
The \fB-H\fR option specifies a hard limit. The \fB-S\fR option specifies a
soft limit. If neither option is specified, \fBulimit\fR sets both limits and
print the soft limit.
.sp
The following options specify the resource whose limits are to be printed or
set. If no option is specified, the file size limit is printed or set.
.sp
.ne 2
.na
\fB\fB-c\fR\fR
.ad
.RS 6n
maximum core file size (in 512-byte blocks)
.RE
.sp
.ne 2
.na
\fB\fB-d\fR\fR
.ad
.RS 6n
maximum size of data segment or heap (in kbytes)
.RE
.sp
.ne 2
.na
\fB\fB-f\fR\fR
.ad
.RS 6n
maximum file size (in 512-byte blocks)
.RE
.sp
.ne 2
.na
\fB\fB-n\fR\fR
.ad
.RS 6n
maximum file descriptor plus 1
.RE
.sp
.ne 2
.na
\fB\fB-s\fR\fR
.ad
.RS 6n
maximum size of stack segment (in kbytes)
.RE
.sp
.ne 2
.na
\fB\fB-t\fR\fR
.ad
.RS 6n
maximum CPU time (in seconds)
.RE
.sp
.ne 2
.na
\fB\fB-v\fR\fR
.ad
.RS 6n
maximum size of virtual memory (in kbytes)
.RE
Run the \fBsysdef\fR(8) command to obtain the maximum possible limits for your
system. The values reported are in hexadecimal, but can be translated into
decimal numbers using the \fBbc\fR(1) utility. See \fBswap\fR(8).)
.sp
As an example of \fBulimit\fR, to limit the size of a core file dump to 0
Megabytes, type the following:
.sp
.in +2
.nf
\fBulimit -c 0\fR
.fi
.in -2
.sp
.RE
.sp
.ne 2
.na
\fB\fBumask\fR [ \fInnn\fR ]\fR
.ad
.sp .6
.RS 4n
The user file-creation mask is set to \fInnn\fR (see \fBumask\fR(1)). If
\fInnn\fR is omitted, the current value of the mask is printed.
.RE
.sp
.ne 2
.na
\fB\fBunset\fR [ \fIname\fR .\|.\|. ]\fR
.ad
.sp .6
.RS 4n
For each \fIname\fR, remove the corresponding variable or function value. The
variables \fBPATH\fR, \fBPS1\fR, \fBPS2\fR, \fBMAILCHECK\fR, and \fBIFS\fR
cannot be unset.
.RE
.sp
.ne 2
.na
\fB\fBwait\fR [ \fIn\fR ]\fR
.ad
.sp .6
.RS 4n
Wait for your background process whose process id is \fIn\fR and report its
termination status. If \fIn\fR is omitted, all your shell's currently active
background processes are waited for and the return code is zero.
.RE
.SS "Invocation"
.LP
If the shell is invoked through \fBexec\fR(2) and the first character of
argument zero is \fB\(mi\fR, commands are initially read from
\fB/etc/profile\fR and from \fB$HOME/.profile\fR, if such files exist.
Thereafter, commands are read as described below, which is also the case when
the shell is invoked as \fB/usr/bin/sh\fR. The flags below are interpreted by
the shell on invocation only. \fBNote:\fR Unless the \fB-c\fR or \fB-s\fR flag
is specified, the first argument is assumed to be the name of a file containing
commands, and the remaining arguments are passed as positional parameters to
that command file:
.sp
.ne 2
.na
\fB\fB-c\fR\fI\| string\fR\fR
.ad
.RS 15n
If the \fB-c\fR flag is present commands are read from \fIstring\fR.
.RE
.sp
.ne 2
.na
\fB\fB-i\fR\fR
.ad
.RS 15n
If the \fB-i\fR flag is present or if the shell input and output are attached
to a terminal, this shell is \fBinteractive\fR. In this case, TERMINATE is
ignored (so that \fBkill 0\fR does not kill an interactive shell) and INTERRUPT
is caught and ignored (so that \fBwait\fR is interruptible). In all cases, QUIT
is ignored by the shell.
.RE
.sp
.ne 2
.na
\fB\fB-p\fR\fR
.ad
.RS 15n
If the \fB-p\fR flag is present, the shell does not set the effective user and
group IDs to the real user and group IDs.
.RE
.sp
.ne 2
.na
\fB\fB-r\fR\fR
.ad
.RS 15n
If the \fB-r\fR flag is present the shell is a restricted shell (see
\fBrsh\fR(8)).
.RE
.sp
.ne 2
.na
\fB\fB-s\fR\fR
.ad
.RS 15n
If the \fB-s\fR flag is present or if no arguments remain, commands are read
from the standard input. Any remaining arguments specify the positional
parameters. Shell output (except for \fBSpecial Commands\fR) is written to file
descriptor 2.
.RE
.sp
.LP
The remaining flags and arguments are described under the \fBset\fR command
above.
.SS "Job Control (jsh)"
.LP
When the shell is invoked as \fBjsh\fR, Job Control is enabled in addition to
all of the functionality described previously for \fBsh\fR. Typically, Job
Control is enabled for the interactive shell only. Non-interactive shells
typically do not benefit from the added functionality of Job Control.
.sp
.LP
With Job Control enabled, every command or pipeline the user enters at the
terminal is called a \fIjob\fR. All jobs exist in one of the following states:
foreground, background, or stopped. These terms are defined as follows:
.RS +4
.TP
1.
A job in the foreground has read and write access to the controlling
terminal.
.RE
.RS +4
.TP
2.
A job in the background is denied read access and has conditional write
access to the controlling terminal (see \fBstty\fR(1)).
.RE
.RS +4
.TP
3.
A stopped job is a job that has been placed in a suspended state, usually as
a result of a \fBSIGTSTP\fR signal (see \fBsignal.h\fR(3HEAD)).
.RE
.sp
.LP
Every job that the shell starts is assigned a positive integer, called a \fIjob
number\fR which is tracked by the shell and is used as an identifier to
indicate a specific job. Additionally, the shell keeps track of the
\fIcurrent\fR and \fIprevious\fR jobs. The \fIcurrent job\fR is the most recent
job to be started or restarted. The \fIprevious job\fR is the first non-current
job.
.sp
.LP
The acceptable syntax for a Job Identifier is of the form:
.sp
.LP
\fB%\fR\fIjobid\fR
.sp
.LP
where \fIjobid\fR can be specified in any of the following formats:
.sp
.ne 2
.na
\fB\fB%\fR or \fB+\fR\fR
.ad
.RS 13n
For the current job.
.RE
.sp
.ne 2
.na
\fB\fB\(mi\fR\fR
.ad
.RS 13n
For the previous job.
.RE
.sp
.ne 2
.na
\fB\fB?\fR\fI<string>\fR\fR
.ad
.RS 13n
Specify the job for which the command line uniquely contains \fIstring\fR.
.RE
.sp
.ne 2
.na
\fB\fIn\fR\fR
.ad
.RS 13n
For job number \fIn\fR.
.RE
.sp
.ne 2
.na
\fB\fIpref\fR\fR
.ad
.RS 13n
Where \fIpref\fR is a unique prefix of the command name. For example, if the
command \fBls\fR \fB-l\fR \fIname\fR were running in the background, it could
be referred to as \fB%ls\fR. \fIpref\fR cannot contain blanks unless it is
quoted.
.RE
.sp
.LP
When Job Control is enabled, the following commands are added to the user's
environment to manipulate jobs:
.sp
.ne 2
.na
\fB\fBbg\fR [\fB%\fR\fIjobid .\|.\|.\fR]\fR
.ad
.sp .6
.RS 4n
Resumes the execution of a stopped job in the background. If \fB%\fR\fIjobid\fR
is omitted the current job is assumed.
.RE
.sp
.ne 2
.na
\fB\fBfg\fR [\fB%\fR\fIjobid .\|.\|.\fR]\fR
.ad
.sp .6
.RS 4n
Resumes the execution of a stopped job in the foreground, also moves an
executing background job into the foreground. If \fB%\fR\fIjobid\fR is omitted
the current job is assumed.
.RE
.sp
.ne 2
.na
\fB\fBjobs\fR [\fB-p\fR|\fB-l\fR] [\fB%\fR\fIjobid .\|.\|.\fR]\fR
.ad
.br
.na
\fB\fBjobs\fR \fB-x\fR \fBcommand\fR [\fIarguments\fR]\fR
.ad
.sp .6
.RS 4n
Reports all jobs that are stopped or executing in the background. If
\fB%\fR\fIjobid\fR is omitted, all jobs that are stopped or running in the
background is reported. The following options modify/enhance the output of
\fBjobs\fR:
.sp
.ne 2
.na
\fB\fB-l\fR\fR
.ad
.RS 6n
Report the process group ID and working directory of the jobs.
.RE
.sp
.ne 2
.na
\fB\fB-p\fR\fR
.ad
.RS 6n
Report only the process group ID of the jobs.
.RE
.sp
.ne 2
.na
\fB\fB-x\fR\fR
.ad
.RS 6n
Replace any \fIjobid\fR found in \fIcommand\fR or \fIarguments\fR with the
corresponding process group ID, and then execute \fIcommand\fR passing it
\fIarguments\fR.
.RE
.RE
.sp
.ne 2
.na
\fB\fBkill\fR [ \fB-signal\fR ] \fB%\fR\fIjobid\fR\fR
.ad
.sp .6
.RS 4n
Builtin version of \fBkill\fR to provide the functionality of the \fBkill\fR
command for processes identified with a \fIjobid\fR.
.RE
.sp
.ne 2
.na
\fB\fBstop\fR \fB%\fR\fIjobid .\|.\|.\fR\fR
.ad
.sp .6
.RS 4n
Stops the execution of a background job(s).
.RE
.sp
.ne 2
.na
\fB\fBsuspend\fR\fR
.ad
.sp .6
.RS 4n
Stops the execution of the current shell (but not if it is the login shell).
.RE
.sp
.ne 2
.na
\fB\fBwait\fR [\fB%\fR\fIjobid .\|.\|.\fR]\fR
.ad
.sp .6
.RS 4n
\fBwait\fR builtin accepts a job identifier. If \fB%\fR\fIjobid\fR is omitted
\fBwait\fR behaves as described above under \fBSpecial Commands\fR.
.RE
.SS "Large File Behavior"
.LP
See \fBlargefile\fR(7) for the description of the behavior of \fBsh\fR and
\fBjsh\fR when encountering files greater than or equal to 2 Gbyte ( 2^31
bytes).
.SH EXIT STATUS
.LP
Errors detected by the shell, such as syntax errors, cause the shell to return
a non-zero exit status. If the shell is being used non-interactively execution
of the shell file is abandoned. Otherwise, the shell returns the exit status of
the last command executed (see also the \fBexit\fR command above).
.SS "jsh Only"
.LP
If the shell is invoked as \fBjsh\fR and an attempt is made to exit the shell
while there are stopped jobs, the shell issues one warning:
.sp
.LP
\fBThere are stopped jobs.\fR
.sp
.LP
This is the only message. If another exit attempt is made, and there are still
stopped jobs they are sent a \fBSIGHUP\fR signal from the kernel and the shell
is exited.
.SH FILES
.LP
\fB$HOME/.profile\fR
.sp
.LP
\fB/dev/null\fR
.sp
.LP
\fB/etc/profile\fR
.sp
.LP
\fB/tmp/sh*\fR
.SH ATTRIBUTES
.LP
See \fBattributes\fR(7) for descriptions of the following attributes:
.SS "/usr/bin/sh, /usr/bin/jsh"
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE ATTRIBUTE VALUE
_
CSI Enabled
.TE
.SS "/usr/xpg4/bin/sh"
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE ATTRIBUTE VALUE
_
CSI Enabled
.TE
.SH SEE ALSO
.LP
.BR Intro (1),
.BR bc (1),
.BR echo (1),
.BR getoptcvt (1),
.BR kill (1),
.BR ksh (1),
.BR login (1),
.BR newgrp (1),
.BR pfexec (1),
.BR pfsh (1),
.BR ps (1),
.BR pwd (1),
.BR set (1),
.BR shell_builtins (1),
.BR stty (1),
.BR test (1),
.BR umask (1),
.BR wait (1),
.BR dup (2),
.BR exec (2),
.BR fork (2),
.BR getrlimit (2),
.BR pipe (2),
.BR ulimit (2),
.BR setlocale (3C),
.BR signal.h (3HEAD),
.BR passwd (5),
.BR profile (5),
.BR XPG4 (7),
.BR attributes (7),
.BR environ (7),
.BR largefile (7),
.BR rsh (8),
.BR su (8),
.BR swap (8),
.BR sysdef (8)
.SH WARNINGS
.LP
The use of \fBsetuid\fR shell scripts is \fBstrongly\fR discouraged.
.SH NOTES
.LP
Words used for filenames in input/output redirection are not interpreted for
filename generation (see \fBFile Name Generation\fR section above). For
example, \fBcat file1 >a*\fR createsa file named \fBa*\fR.
.sp
.LP
Because commands in pipelines are run as separate processes, variables set in a
pipeline have no effect on the parent shell.
.sp
.LP
If the input or the output of a \fBwhile\fR or \fBuntil\fR loop is redirected,
the commands in the loop are run in a sub-shell, and variables set or changed
there have no effect on the parent process:
.sp
.in +2
.nf
lastline=
while read line
do
lastline=$line
done < /etc/passwd
echo "lastline=$lastline" # lastline is empty!
.fi
.in -2
.sp
.sp
.LP
In these cases, the input or output can be redirected by using \fBexec\fR, as
in the following example:
.sp
.in +2
.nf
# Save standard input (file descriptor 0) as file
# descriptor 3, and redirect standard input from the file
/etc/passwd:
exec 3<&0 # save standard input as fd 3
exec </etc/passwd # redirect input from file
lastline=
while read line
do
lastline=$line
done
exec 0<&3 # restore standard input
exec 3<&- # close file descriptor 3
echo "$lastline" # lastline
.fi
.in -2
.sp
.sp
.LP
If you get the error message, "\fBcannot fork, too many processes\fR", try
using the \fBwait\fR(1) command to clean up your background processes. If this
doesn't help, the system process table is probably full or you have too many
active foreground processes. There is a limit to the number of process ids
associated with your login, and to the number the system can keep track of.
.sp
.LP
Only the last process in a pipeline can be waited for.
.sp
.LP
If a command is executed, and a command with the same name is installed in a
directory in the search path before the directory where the original command
was found, the shell continues to \fBexec\fR the original command. Use the
\fBhash\fR command to correct this situation.
.sp
.LP
The Bourne shell has a limitation on the effective \fBUID\fR for a process. If
this \fBUID\fR is less than 100 (and not equal to the real UID of the process),
then the \fBUID\fR is reset to the real UID of the process.
.sp
.LP
Because the shell implements both foreground and background jobs in the same
process group, they all receive the same signals, which can lead to unexpected
behavior. It is, therefore, recommended that other job control shells be used,
especially in an interactive environment.
.sp
.LP
When the shell executes a shell script that attempts to execute a non-existent
command interpreter, the shell returns an erroneous diagnostic message that the
shell script file does not exist.
|