~mirabilos/mksh/MAIN

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
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
.\" $MirOS: src/bin/mksh/mksh.1,v 1.460 2018/08/17 20:33:08 tg Exp $
.\" $OpenBSD: ksh.1,v 1.160 2015/07/04 13:27:04 feinerer Exp $
.\"-
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
.\"		2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017,
.\"		2018
.\"	mirabilos <m@mirbsd.org>
.\"
.\" Provided that these terms and disclaimer and all copyright notices
.\" are retained or reproduced in an accompanying document, permission
.\" is granted to deal in this work without restriction, including un‐
.\" limited rights to use, publicly perform, distribute, sell, modify,
.\" merge, give away, or sublicence.
.\"
.\" This work is provided “AS IS” and WITHOUT WARRANTY of any kind, to
.\" the utmost extent permitted by applicable law, neither express nor
.\" implied; without malicious intent or gross negligence. In no event
.\" may a licensor, author or contributor be held liable for indirect,
.\" direct, other damage, loss, or other issues arising in any way out
.\" of dealing in the work, even if advised of the possibility of such
.\" damage or existence of a defect, except proven that it results out
.\" of said person’s immediate fault when using the work as intended.
.\"-
.\" Try to make GNU groff and AT&T nroff more compatible
.\" * ` generates ‘ in gnroff, so use \`
.\" * ' generates ’ in gnroff, \' generates ´, so use \*(aq
.\" * - generates ‐ in gnroff, \- generates −, so .tr it to -
.\"   thus use - for hyphens and \- for minus signs and option dashes
.\" * ~ is size-reduced and placed atop in groff, so use \*(TI
.\" * ^ is size-reduced and placed atop in groff, so use \*(ha
.\" * \(en does not work in nroff, so use \*(en
.\" * <>| are problematic, so redefine and use \*(Lt\*(Gt\*(Ba
.\" Also make sure to use \& *before* a punctuation char that is to not
.\" be interpreted as punctuation, and especially with two-letter words
.\" but also (after) a period that does not end a sentence (“e.g.\&”).
.\" The section after the "doc" macropackage has been loaded contains
.\" additional code to convene between the UCB mdoc macropackage (and
.\" its variant as BSD mdoc in groff) and the GNU mdoc macropackage.
.\"
.ie \n(.g \{\
.	if \*[.T]ascii .tr \-\N'45'
.	if \*[.T]latin1 .tr \-\N'45'
.	if \*[.T]utf8 .tr \-\N'45'
.	ds <= \[<=]
.	ds >= \[>=]
.	ds Rq \[rq]
.	ds Lq \[lq]
.	ds sL \(aq
.	ds sR \(aq
.	if \*[.T]utf8 .ds sL `
.	if \*[.T]ps .ds sL `
.	if \*[.T]utf8 .ds sR '
.	if \*[.T]ps .ds sR '
.	ds aq \(aq
.	ds TI \(ti
.	ds ha \(ha
.	ds en \(en
.\}
.el \{\
.	ds aq '
.	ds TI ~
.	ds ha ^
.	ds en \(em
.\}
.\"
.\" Implement .Dd with the Mdocdate RCS keyword
.\"
.rn Dd xD
.de Dd
.ie \\$1$Mdocdate: \{\
.	xD \\$2 \\$3, \\$4
.\}
.el .xD \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8
..
.\"
.\" .Dd must come before definition of .Mx, because when called
.\" with -mandoc, it might implement .Mx itself, but we want to
.\" use our own definition. And .Dd must come *first*, always.
.\"
.Dd $Mdocdate: August 17 2018 $
.\"
.\" Check which macro package we use, and do other -mdoc setup.
.\"
.ie \n(.g \{\
.	if \*[.T]utf8 .tr \[la]\*(Lt
.	if \*[.T]utf8 .tr \[ra]\*(Gt
.	ie d volume-ds-1 .ds tT gnu
.	el .ds tT bsd
.\}
.el .ds tT ucb
.\"
.\" Implement .Mx (MirBSD)
.\"
.ie "\*(tT"gnu" \{\
.	eo
.	de Mx
.	nr curr-font \n[.f]
.	nr curr-size \n[.ps]
.	ds str-Mx \f[\n[curr-font]]\s[\n[curr-size]u]
.	ds str-Mx1 \*[Tn-font-size]\%MirOS\*[str-Mx]
.	if !\n[arg-limit] \
.	if \n[.$] \{\
.	ds macro-name Mx
.	parse-args \$@
.	\}
.	if (\n[arg-limit] > \n[arg-ptr]) \{\
.	nr arg-ptr +1
.	ie (\n[type\n[arg-ptr]] == 2) \
.	as str-Mx1 \~\*[arg\n[arg-ptr]]
.	el \
.	nr arg-ptr -1
.	\}
.	ds arg\n[arg-ptr] "\*[str-Mx1]
.	nr type\n[arg-ptr] 2
.	ds space\n[arg-ptr] "\*[space]
.	nr num-args (\n[arg-limit] - \n[arg-ptr])
.	nr arg-limit \n[arg-ptr]
.	if \n[num-args] \
.	parse-space-vector
.	print-recursive
..
.	ec
.	ds sP \s0
.	ds tN \*[Tn-font-size]
.\}
.el \{\
.	de Mx
.	nr cF \\n(.f
.	nr cZ \\n(.s
.	ds aa \&\f\\n(cF\s\\n(cZ
.	if \\n(aC==0 \{\
.		ie \\n(.$==0 \&MirOS\\*(aa
.		el .aV \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8 \\$9
.	\}
.	if \\n(aC>\\n(aP \{\
.		nr aP \\n(aP+1
.		ie \\n(C\\n(aP==2 \{\
.			as b1 \&MirOS\ #\&\\*(A\\n(aP\\*(aa
.			ie \\n(aC>\\n(aP \{\
.				nr aP \\n(aP+1
.				nR
.			\}
.			el .aZ
.		\}
.		el \{\
.			as b1 \&MirOS\\*(aa
.			nR
.		\}
.	\}
..
.\}
.\"-
.Dt MKSH 1
.Os MirBSD
.Sh NAME
.Nm mksh ,
.Nm sh
.Nd MirBSD Korn shell
.Sh SYNOPSIS
.Nm
.Bk -words
.Op Fl +abCefhiklmnprUuvXx
.Oo
.Fl T Oo Ar \&! Oc Ns Ar tty
\*(Ba
.Ar \&\-
.Oc
.Op Fl +o Ar option
.Oo
.Fl c Ar string \*(Ba
.Fl s \*(Ba
.Ar file
.Op Ar argument ...
.Oc
.Ek
.Nm builtin-name
.Op Ar argument ...
.Sh DESCRIPTION
.Nm
is a command interpreter intended for both interactive and shell
script use.
Its command language is a superset of the
.Xr sh C
shell language and largely compatible to the original Korn shell.
At times, this manual page may give scripting advice; while it
sometimes does take portable shell scripting or various standards
into account all information is first and foremost presented with
.Nm
in mind and should be taken as such.
.Ss I use Android, OS/2, etc. so what...?
Please see the FAQ at the end of this document.
.Ss Invocation
Most builtins can be called directly, for example if a link points from its
name to the shell; not all make sense, have been tested or work at all though.
.Pp
The options are as follows:
.Bl -tag -width XcXstring
.It Fl c Ar string
.Nm
will execute the command(s) contained in
.Ar string .
.It Fl i
Interactive shell.
A shell that reads commands from standard input is
.Dq interactive
if this
option is used or if both standard input and standard error are attached
to a
.Xr tty 4 .
An interactive shell has job control enabled, ignores the
.Dv SIGINT ,
.Dv SIGQUIT
and
.Dv SIGTERM
signals, and prints prompts before reading input (see the
.Ev PS1
and
.Ev PS2
parameters).
It also processes the
.Ev ENV
parameter or the
.Pa mkshrc
file (see below).
For non-interactive shells, the
.Ic trackall
option is on by default (see the
.Ic set
command below).
.It Fl l
Login shell.
If the basename the shell is called with (i.e. argv[0])
starts with
.Ql \-
or if this option is used,
the shell is assumed to be a login shell; see
.Sx Startup files
below.
.It Fl p
Privileged shell.
A shell is
.Dq privileged
if the real user ID or group ID does not match the
effective user ID or group ID (see
.Xr getuid 2
and
.Xr getgid 2 ) .
Clearing the privileged option causes the shell to set
its effective user ID (group ID) to its real user ID (group ID).
For further implications, see
.Sx Startup files .
If the shell is privileged and this flag is not explicitly set, the
.Dq privileged
option is cleared automatically after processing the startup files.
.It Fl r
Restricted shell.
A shell is
.Dq restricted
if this
option is used.
The following restrictions come into effect after the shell processes any
profile and
.Ev ENV
files:
.Pp
.Bl -bullet -compact
.It
The
.Ic cd
.Po and Ic chdir Pc
command is disabled.
.It
The
.Ev SHELL ,
.Ev ENV
and
.Ev PATH
parameters cannot be changed.
.It
Command names can't be specified with absolute or relative paths.
.It
The
.Fl p
option of the built-in command
.Ic command
can't be used.
.It
Redirections that create files can't be used (i.e.\&
.Dq Li \*(Gt ,
.Dq Li \*(Gt\*(Ba ,
.Dq Li \*(Gt\*(Gt ,
.Dq Li \*(Lt\*(Gt ) .
.El
.It Fl s
The shell reads commands from standard input; all non-option arguments
are positional parameters.
.It Fl T Ar name
Spawn
.Nm
on the
.Xr tty 4
device given.
The paths
.Ar name ,
.Pa /dev/ttyC Ns Ar name
and
.Pa /dev/tty Ns Ar name
are attempted in order.
Unless
.Ar name
begins with an exclamation mark
.Pq Ql \&! ,
this is done in a subshell and returns immediately.
If
.Ar name
is a dash
.Pq Ql \&\- ,
detach from controlling terminal (daemonise) instead.
.El
.Pp
In addition to the above, the options described in the
.Ic set
built-in command can also be used on the command line:
both
.Op Fl +abCefhkmnuvXx
and
.Op Fl +o Ar option
can be used for single letter or long options, respectively.
.Pp
If neither the
.Fl c
nor the
.Fl s
option is specified, the first non-option argument specifies the name
of a file the shell reads commands from.
If there are no non-option
arguments, the shell reads commands from the standard input.
The name of the shell (i.e. the contents of $0)
is determined as follows: if the
.Fl c
option is used and there is a non-option argument, it is used as the name;
if commands are being read from a file, the file is used as the name;
otherwise, the basename the shell was called with (i.e. argv[0]) is used.
.Pp
The exit status of the shell is 127 if the command file specified on the
command line could not be opened, or non-zero if a fatal syntax error
occurred during the execution of a script.
In the absence of fatal errors,
the exit status is that of the last command executed, or zero if no
command is executed.
.Ss Startup files
For the actual location of these files, see
.Sx FILES .
A login shell processes the system profile first.
A privileged shell then processes the suid profile.
A non-privileged login shell processes the user profile next.
A non-privileged interactive shell checks the value of the
.Ev ENV
parameter after subjecting it to parameter, command, arithmetic and tilde
.Pq Ql \*(TI
substitution; if unset or empty, the user mkshrc profile is processed;
otherwise, if a file whose name is the substitution result exists,
it is processed; non-existence is silently ignored.
A privileged shell then drops privileges if neither was the
.Fl p
option given on the command line nor set during execution of the startup files.
.Ss Command syntax
The shell begins parsing its input by removing any backslash-newline
combinations, then breaking it into
.Em words .
Words (which are sequences of characters) are delimited by unquoted whitespace
characters (space, tab and newline) or meta-characters
.Po
.Ql \*(Lt ,
.Ql \*(Gt ,
.Ql \*(Ba ,
.Ql \&; ,
.Ql \&( ,
.Ql \&)
and
.Ql &
.Pc .
Aside from delimiting words, spaces and tabs are ignored, while newlines
usually delimit commands.
The meta-characters are used in building the following
.Em tokens :
.Dq Li \*(Lt ,
.Dq Li \*(Lt& ,
.Dq Li \*(Lt\*(Lt ,
.Dq Li \*(Lt\*(Lt\*(Lt ,
.Dq Li \*(Gt ,
.Dq Li \*(Gt& ,
.Dq Li \*(Gt\*(Gt ,
.Dq Li &\*(Gt ,
etc. are used to specify redirections (see
.Sx Input/output redirection
below);
.Dq Li \*(Ba
is used to create pipelines;
.Dq Li \*(Ba&
is used to create co-processes (see
.Sx Co-processes
below);
.Dq Li \&;
is used to separate commands;
.Dq Li &
is used to create asynchronous pipelines;
.Dq Li &&
and
.Dq Li \*(Ba\*(Ba
are used to specify conditional execution;
.Dq Li \&;; ,
.Dq Li \&;&
and
.Dq Li \&;\*(Ba
are used in
.Ic case
statements;
.Dq Li \&(( ... \&))
is used in arithmetic expressions;
and lastly,
.Dq Li \&( ... \&)
is used to create subshells.
.Pp
Whitespace and meta-characters can be quoted individually using a backslash
.Pq Ql \e ,
or in groups using double
.Pq Ql \&"
or single
.Pq Dq Li \*(aq
quotes.
Note that the following characters are also treated specially by the
shell and must be quoted if they are to represent themselves:
.Ql \e ,
.Ql \&" ,
.Dq Li \*(aq ,
.Ql # ,
.Ql $ ,
.Ql \` ,
.Ql \*(TI ,
.Ql { ,
.Ql } ,
.Ql * ,
.Ql \&?
and
.Ql \&[ .
The first three of these are the above mentioned quoting characters (see
.Sx Quoting
below);
.Ql # ,
if used at the beginning of a word, introduces a comment \*(en everything after
the
.Ql #
up to the nearest newline is ignored;
.Ql $
is used to introduce parameter, command and arithmetic substitutions (see
.Sx Substitution
below);
.Ql \`
introduces an old-style command substitution (see
.Sx Substitution
below);
.Ql \*(TI
begins a directory expansion (see
.Sx Tilde expansion
below);
.Ql {
and
.Ql }
delimit
.Xr csh 1 Ns -style
alternations (see
.Sx Brace expansion
below);
and finally,
.Ql * ,
.Ql \&?
and
.Ql \&[
are used in file name generation (see
.Sx File name patterns
below).
.Pp
As words and tokens are parsed, the shell builds commands, of which there
are two basic types:
.Em simple-commands ,
typically programmes that are executed, and
.Em compound-commands ,
such as
.Ic for
and
.Ic if
statements, grouping constructs and function definitions.
.Pp
A simple-command consists of some combination of parameter assignments
(see
.Sx Parameters
below),
input/output redirections (see
.Sx Input/output redirections
below)
and command words; the only restriction is that parameter assignments come
before any command words.
The command words, if any, define the command
that is to be executed and its arguments.
The command may be a shell built-in command, a function
or an external command
(i.e. a separate executable file that is located using the
.Ev PATH
parameter; see
.Sx Command execution
below).
Note that all command constructs have an exit status: for external commands,
this is related to the status returned by
.Xr wait 2
(if the command could not be found, the exit status is 127; if it could not
be executed, the exit status is 126); the exit status of other command
constructs (built-in commands, functions, compound-commands, pipelines, lists,
etc.) are all well-defined and are described where the construct is
described.
The exit status of a command consisting only of parameter
assignments is that of the last command substitution performed during the
parameter assignment or 0 if there were no command substitutions.
.Pp
Commands can be chained together using the
.Dq Li \*(Ba
token to form pipelines, in which the standard output of each command but the
last is piped (see
.Xr pipe 2 )
to the standard input of the following command.
The exit status of a pipeline is that of its last command, unless the
.Ic pipefail
option is set (see there).
All commands of a pipeline are executed in separate subshells;
this is allowed by POSIX but differs from both variants of
.At
.Nm ksh ,
where all but the last command were executed in subshells; see the
.Ic read
builtin's description for implications and workarounds.
A pipeline may be prefixed by the
.Dq Li \&!
reserved word which causes the exit status of the pipeline to be logically
complemented: if the original status was 0, the complemented status will be 1;
if the original status was not 0, the complemented status will be 0.
.Pp
.Em Lists
of commands can be created by separating pipelines by any of the following
tokens:
.Dq Li && ,
.Dq Li \*(Ba\*(Ba ,
.Dq Li & ,
.Dq Li \*(Ba&
and
.Dq Li \&; .
The first two are for conditional execution:
.Dq Ar cmd1 No && Ar cmd2
executes
.Ar cmd2
only if the exit status of
.Ar cmd1
is zero;
.Dq Li \*(Ba\*(Ba
is the opposite \*(en
.Ar cmd2
is executed only if the exit status of
.Ar cmd1
is non-zero.
.Dq Li &&
and
.Dq Li \*(Ba\*(Ba
have equal precedence which is higher than that of
.Dq Li & ,
.Dq Li \*(Ba&
and
.Dq Li \&; ,
which also have equal precedence.
Note that the
.Dq Li &&
and
.Dq Li \*(Ba\*(Ba
operators are
.Qq left-associative .
For example, both of these commands will print only
.Qq bar :
.Bd -literal -offset indent
$ false && echo foo \*(Ba\*(Ba echo bar
$ true \*(Ba\*(Ba echo foo && echo bar
.Ed
.Pp
The
.Dq Li &
token causes the preceding command to be executed asynchronously; that is,
the shell starts the command but does not wait for it to complete (the shell
does keep track of the status of asynchronous commands; see
.Sx Job control
below).
When an asynchronous command is started when job control is disabled
(i.e. in most scripts), the command is started with signals
.Dv SIGINT
and
.Dv SIGQUIT
ignored and with input redirected from
.Pa /dev/null
(however, redirections specified in the asynchronous command have precedence).
The
.Dq Li \*(Ba&
operator starts a co-process which is a special kind of asynchronous process
(see
.Sx Co-processes
below).
Note that a command must follow the
.Dq Li &&
and
.Dq Li \*(Ba\*(Ba
operators, while it need not follow
.Dq Li & ,
.Dq Li \*(Ba&
or
.Dq Li \&; .
The exit status of a list is that of the last command executed, with the
exception of asynchronous lists, for which the exit status is 0.
.Pp
Compound commands are created using the following reserved words.
These words
are only recognised if they are unquoted and if they are used as the first
word of a command (i.e. they can't be preceded by parameter assignments or
redirections):
.Bd -literal -offset indent
case     else     function     then      !       (
do       esac     if           time      [[      ((
done     fi       in           until     {
elif     for      select       while     }
.Ed
.Pp
In the following compound command descriptions, command lists (denoted as
.Em list )
that are followed by reserved words must end with a semicolon, a newline or
a (syntactically correct) reserved word.
For example, the following are all valid:
.Bd -literal -offset indent
$ { echo foo; echo bar; }
$ { echo foo; echo bar\*(Ltnewline\*(Gt}
$ { { echo foo; echo bar; } }
.Ed
.Pp
This is not valid:
.Pp
.Dl $ { echo foo; echo bar }
.Bl -tag -width 4n
.It Pq Ar list
Execute
.Ar list
in a subshell.
There is no implicit way to pass environment changes from a
subshell back to its parent.
.It { Ar list ; No }
Compound construct;
.Ar list
is executed, but not in a subshell.
Note that
.Dq Li {
and
.Dq Li }
are reserved words, not meta-characters.
.It Xo case Ar word No in
.Oo Op \&(
.Ar pattern
.Op \*(Ba Ar pattern
.No ... Ns )
.Ar list
.Ic terminator
.Oc No ... esac
.Xc
The
.Ic case
statement attempts to match
.Ar word
against a specified
.Ar pattern ;
the
.Ar list
associated with the first successfully matched pattern is executed.
Patterns used in
.Ic case
statements are the same as those used for file name patterns except that the
restrictions regarding
.Ql \&.
and
.Ql /
are dropped.
Note that any unquoted space before and after a pattern is
stripped; any space within a pattern must be quoted.
Both the word and the
patterns are subject to parameter, command and arithmetic substitution, as
well as tilde substitution.
.Pp
For historical reasons, open and close braces may be used instead of
.Ic in
and
.Ic esac
e.g.\&
.Ic case $foo { *) echo bar ;; } .
.Pp
The list
.Ic terminator Ns s
are:
.Bl -tag -width 4n
.It Dq Li ;;
Terminate after the list.
.It Dq Li \&;&
Fall through into the next list.
.It Dq Li \&;\*(Ba
Evaluate the remaining pattern-list tuples.
.El
.Pp
The exit status of a
.Ic case
statement is that of the executed
.Ar list ;
if no
.Ar list
is executed, the exit status is zero.
.It Xo for Ar name
.Oo in Ar word No ... Oc ;
.No do Ar list ; No done
.Xc
For each
.Ar word
in the specified word list, the parameter
.Ar name
is set to the word and
.Ar list
is executed.
If
.Ic in
is not used to specify a word list, the positional parameters ($1, $2,
etc.) are used instead.
For historical reasons, open and close braces may be used instead of
.Ic do
and
.Ic done
e.g.\&
.Ic for i; { echo $i; } .
The exit status of a
.Ic for
statement is the last exit status of
.Ar list ;
if
.Ar list
is never executed, the exit status is zero.
.It Xo if Ar list ;
.No then Ar list ;
.Oo elif Ar list ;
.No then Ar list ; Oc
.No ...
.Oo else Ar list ; Oc
.No fi
.Xc
If the exit status of the first
.Ar list
is zero, the second
.Ar list
is executed; otherwise, the
.Ar list
following the
.Ic elif ,
if any, is executed with similar consequences.
If all the lists following the
.Ic if
and
.Ic elif Ns s
fail (i.e. exit with non-zero status), the
.Ar list
following the
.Ic else
is executed.
The exit status of an
.Ic if
statement is that of non-conditional
.Ar list
that is executed; if no non-conditional
.Ar list
is executed, the exit status is zero.
.It Xo select Ar name
.Oo in Ar word No ... Oc ;
.No do Ar list ; No done
.Xc
The
.Ic select
statement provides an automatic method of presenting the user with a menu and
selecting from it.
An enumerated list of the specified
.Ar word Ns (s)
is printed on standard error, followed by a prompt
.Po
.Ev PS3 :
normally
.Dq Li #?\ \&
.Pc .
A number corresponding to one of the enumerated words is then read from
standard input,
.Ar name
is set to the selected word (or unset if the selection is not valid),
.Ev REPLY
is set to what was read (leading/trailing space is stripped), and
.Ar list
is executed.
If a blank line (i.e. zero or more
.Ev IFS
octets) is entered, the menu is reprinted without executing
.Ar list .
.Pp
When
.Ar list
completes, the enumerated list is printed if
.Ev REPLY
is empty, the prompt is printed, and so on.
This process continues until an end-of-file
is read, an interrupt is received, or a
.Ic break
statement is executed inside the loop.
If
.Dq in Ar word ...
is omitted, the positional parameters are used
(i.e. $1, $2, etc.).
For historical reasons, open and close braces may be used instead of
.Ic do
and
.Ic done
e.g.\&
.Ic select i; { echo $i; } .
The exit status of a
.Ic select
statement is zero if a
.Ic break
statement is used to exit the loop, non-zero otherwise.
.It Xo until Ar list ;
.No do Ar list ;
.No done
.Xc
This works like
.Ic while ,
except that the body is executed only while the exit status of the first
.Ar list
is non-zero.
.It Xo while Ar list ;
.No do Ar list ;
.No done
.Xc
A
.Ic while
is a pre-checked loop.
Its body is executed as often as the exit status of the first
.Ar list
is zero.
The exit status of a
.Ic while
statement is the last exit status of the
.Ar list
in the body of the loop; if the body is not executed, the exit status is zero.
.It Xo function Ar name
.No { Ar list ; No }
.Xc
Defines the function
.Ar name
(see
.Sx Functions
below).
Note that redirections specified after a function definition are
performed whenever the function is executed, not when the function definition
is executed.
.It Ar name Ns \&() Ar command
Mostly the same as
.Ic function
(see
.Sx Functions
below).
Whitespace (space or tab) after
.Ar name
will be ignored most of the time.
.It Xo function Ar name Ns \&()
.No { Ar list ; No }
.Xc
The same as
.Ar name Ns \&()
.Pq Nm bash Ns ism .
The
.Ic function
keyword is ignored.
.It Xo Ic time Op Fl p
.Op Ar pipeline
.Xc
The
.Sx Command execution
section describes the
.Ic time
reserved word.
.It \&(( Ar expression No ))
The arithmetic expression
.Ar expression
is evaluated; equivalent to
.Dq Li let \&" Ns Ar expression Ns \&"
(see
.Sx Arithmetic expressions
and the
.Ic let
command, below) in a compound construct.
.It Bq Bq Ar \ \&expression\ \&
Similar to the
.Ic test
and
.Ic \&[ ... \&]
commands (described later), with the following exceptions:
.Bl -bullet
.It
Field splitting and file name generation are not performed on arguments.
.It
The
.Fl a
.Pq AND
and
.Fl o
.Pq OR
operators are replaced with
.Dq Li &&
and
.Dq Li \*(Ba\*(Ba ,
respectively.
.It
Operators (e.g.\&
.Dq Li \-f ,
.Dq Li = ,
.Dq Li \&! )
must be unquoted.
.It
Parameter, command and arithmetic substitutions are performed as expressions
are evaluated and lazy expression evaluation is used for the
.Dq Li &&
and
.Dq Li \*(Ba\*(Ba
operators.
This means that in the following statement,
.Ic $(\*(Ltfoo)
is evaluated if and only if the file
.Pa foo
exists and is readable:
.Bd -literal -offset indent
$ [[ \-r foo && $(\*(Ltfoo) = b*r ]]
.Ed
.It
The second operand of the
.Dq Li !=
and
.Dq Li =
expressions are a subset of patterns (e.g. the comparison
.Ic \&[[ foobar = f*r ]]
succeeds).
This even works indirectly:
.Bd -literal -offset indent
$ bar=foobar; baz=\*(aqf*r\*(aq
$ [[ $bar = $baz ]]; echo $?
$ [[ $bar = \&"$baz" ]]; echo $?
.Ed
.Pp
Perhaps surprisingly, the first comparison succeeds,
whereas the second doesn't.
This does not apply to all extglob metacharacters, currently.
.El
.El
.Ss Quoting
Quoting is used to prevent the shell from treating characters or words
specially.
There are three methods of quoting.
First,
.Ql \e
quotes the following character, unless it is at the end of a line, in which
case both the
.Ql \e
and the newline are stripped.
Second, a single quote
.Pq Dq Li \*(aq
quotes everything up to the next single quote (this may span lines).
Third, a double quote
.Pq Ql \&"
quotes all characters, except
.Ql $ ,
.Ql \e
and
.Ql \` ,
up to the next unescaped double quote.
.Ql $
and
.Ql \`
inside double quotes have their usual meaning (i.e. parameter, arithmetic
or command substitution) except no field splitting is carried out on the
results of double-quoted substitutions, and the old-style form of command
substitution has backslash-quoting for double quotes enabled.
If a
.Ql \e
inside a double-quoted string is followed by
.Ql \&" ,
.Ql $ ,
.Ql \e
or
.Ql \` ,
only the
.Ql \e
is removed, i.e. the combination is replaced by the second character;
if it is followed by a newline, both the
.Ql \e
and the newline are stripped; otherwise, both the
.Ql \e
and the character following are unchanged.
.Pp
If a single-quoted string is preceded by an unquoted
.Ql $ ,
C style backslash expansion (see below) is applied (even single quote
characters inside can be escaped and do not terminate the string then);
the expanded result is treated as any other single-quoted string.
If a double-quoted string is preceded by an unquoted
.Ql $ ,
the
.Ql $
is simply ignored.
.Ss Backslash expansion
In places where backslashes are expanded, certain C and
.At
.Nm ksh
or GNU
.Nm bash
style escapes are translated.
These include
.Dq Li \ea ,
.Dq Li \eb ,
.Dq Li \ef ,
.Dq Li \en ,
.Dq Li \er ,
.Dq Li \et ,
.Dq Li \eU######## ,
.Dq Li \eu####
and
.Dq Li \ev .
For
.Dq Li \eU########
and
.Dq Li \eu#### ,
.Dq #
means a hexadecimal digit, of which there may be none up to four or eight;
these escapes translate a Universal Coded Character Set codepoint to UTF-8.
Furthermore,
.Dq Li \eE
and
.Dq Li \ee
expand to the escape character.
.Pp
In the
.Ic print
builtin mode,
.Dq Li \e" ,
.Dq Li \e\*(aq
and
.Dq Li \e?
are explicitly excluded;
octal sequences must have the none up to three octal digits
.Dq #
prefixed with the digit zero
.Pq Dq Li \e0### ;
hexadecimal sequences
.Dq Li \ex##
are limited to none up to two hexadecimal digits
.Dq # ;
both octal and hexadecimal sequences convert to raw octets;
.Dq Li \e# ,
where # is none of the above, translates to \e# (backslashes are retained).
.Pp
Backslash expansion in the C style mode slightly differs: octal sequences
.Dq Li \e###
must have no digit zero prefixing the one up to three octal digits
.Dq #
and yield raw octets; hexadecimal sequences
.Dq Li \ex#*
greedily eat up as many hexadecimal digits
.Dq #
as they can and terminate with the first non-hexadecimal digit;
these translate a Universal Coded Character Set codepoint to UTF-8.
The sequence
.Dq Li \ec# ,
where
.Dq #
is any octet, translates to Ctrl-# (which basically means,
.Dq Li \ec?
becomes DEL, everything else is bitwise ANDed with 0x1F).
Finally,
.Dq Li \e# ,
where # is none of the above, translates to # (has the backslash trimmed),
even if it is a newline.
.Ss Aliases
There are two types of aliases: normal command aliases and tracked aliases.
Command aliases are normally used as a short hand for a long or often used
command.
The shell expands command aliases (i.e. substitutes the alias name
for its value) when it reads the first word of a command.
An expanded alias is re-processed to check for more aliases.
If a command alias ends in a
space or tab, the following word is also checked for alias expansion.
The alias expansion process stops when a word that is not an alias is found,
when a quoted word is found, or when an alias word that is currently being
expanded is found.
Aliases are specifically an interactive feature: while they do happen
to work in scripts and on the command line in some cases, aliases are
expanded during lexing, so their use must be in a separate command tree
from their definition; otherwise, the alias will not be found.
Noticeably, command lists (separated by semicolon, in command substitutions
also by newline) may be one same parse tree.
.Pp
The following command aliases are defined automatically by the shell:
.Bd -literal -offset indent
autoload=\*(aq\e\ebuiltin typeset \-fu\*(aq
functions=\*(aq\e\ebuiltin typeset \-f\*(aq
hash=\*(aq\e\ebuiltin alias \-t\*(aq
history=\*(aq\e\ebuiltin fc \-l\*(aq
integer=\*(aq\e\ebuiltin typeset \-i\*(aq
local=\*(aq\e\ebuiltin typeset\*(aq
login=\*(aq\e\ebuiltin exec login\*(aq
nameref=\*(aq\e\ebuiltin typeset \-n\*(aq
nohup=\*(aqnohup \*(aq
r=\*(aq\e\ebuiltin fc \-e \-\*(aq
type=\*(aq\e\ebuiltin whence \-v\*(aq
.Ed
.Pp
Tracked aliases allow the shell to remember where it found a particular
command.
The first time the shell does a path search for a command that is
marked as a tracked alias, it saves the full path of the command.
The next
time the command is executed, the shell checks the saved path to see that it
is still valid, and if so, avoids repeating the path search.
Tracked aliases can be listed and created using
.Ic alias Fl t .
Note that changing the
.Ev PATH
parameter clears the saved paths for all tracked aliases.
If the
.Ic trackall
option is set (i.e.\&
.Ic set Fl o Ic trackall
or
.Ic set Fl h ) ,
the shell tracks all commands.
This option is set automatically for non-interactive shells.
For interactive shells, only the following commands are
automatically tracked:
.Xr cat 1 ,
.Xr cc 1 ,
.Xr chmod 1 ,
.Xr cp 1 ,
.Xr date 1 ,
.Xr ed 1 ,
.Xr emacs 1 ,
.Xr grep 1 ,
.Xr ls 1 ,
.Xr make 1 ,
.Xr mv 1 ,
.Xr pr 1 ,
.Xr rm 1 ,
.Xr sed 1 ,
.Xr sh 1 ,
.Xr vi 1
and
.Xr who 1 .
.Ss Substitution
The first step the shell takes in executing a simple-command is to perform
substitutions on the words of the command.
There are three kinds of
substitution: parameter, command and arithmetic.
Parameter substitutions,
which are described in detail in the next section, take the form
.Pf $ Ns Ar name
or
.Pf ${ Ns Ar ... Ns } ;
command substitutions take the form
.Pf $( Ns Ar command Ns \&)
or (deprecated)
.Pf \` Ns Ar command Ns \`
or (executed in the current environment)
.Pf ${\ \& Ar command Ns \&;}
and strip trailing newlines;
and arithmetic substitutions take the form
.Pf $(( Ns Ar expression Ns )) .
Parsing the current-environment command substitution requires a space,
tab or newline after the opening brace and that the closing brace be
recognised as a keyword (i.e. is preceded by a newline or semicolon).
They are also called funsubs (function substitutions) and behave like
functions in that
.Ic local
and
.Ic return
work, and in that
.Ic exit
terminates the parent shell; shell options are shared.
.Pp
Another variant of substitution are the valsubs (value substitutions)
.Pf ${\*(Ba\& Ns Ar command Ns \&;}
which are also executed in the current environment, like funsubs, but
share their I/O with the parent; instead, they evaluate to whatever
the, initially empty, expression-local variable
.Ev REPLY
is set to within the
.Ar command Ns s .
.Pp
If a substitution appears outside of double quotes, the results of the
substitution are generally subject to word or field splitting according to
the current value of the
.Ev IFS
parameter.
The
.Ev IFS
parameter specifies a list of octets which are used to break a string up
into several words; any octets from the set space, tab and newline that
appear in the
.Ev IFS
octets are called
.Dq IFS whitespace .
Sequences of one or more
.Ev IFS
whitespace octets, in combination with zero or one
.Pf non- Ev IFS
whitespace octets, delimit a field.
As a special case, leading and trailing
.Ev IFS
whitespace is stripped (i.e. no leading or trailing empty field
is created by it); leading or trailing
.Pf non- Ev IFS
whitespace does create an empty field.
.Pp
Example: If
.Ev IFS
is set to
.Dq Li \*(Ltspace\*(Gt:
and VAR is set to
.Dq Li \*(Ltspace\*(GtA\*(Ltspace\*(Gt:\*(Ltspace\*(Gt\*(Ltspace\*(GtB::D ,
the substitution for $VAR results in four fields:
.Dq Li A ,
.Dq Li B ,
.Dq
(an empty field) and
.Dq Li D .
Note that if the
.Ev IFS
parameter is set to the empty string, no field splitting is done;
if it is unset, the default value of space, tab and newline is used.
.Pp
Also, note that the field splitting applies only to the immediate result of
the substitution.
Using the previous example, the substitution for $VAR:E
results in the fields:
.Dq Li A ,
.Dq Li B ,
.Dq
and
.Dq Li D:E ,
not
.Dq Li A ,
.Dq Li B ,
.Dq ,
.Dq Li D
and
.Dq Li E .
This behavior is POSIX compliant, but incompatible with some other shell
implementations which do field splitting on the word which contained the
substitution or use
.Dv IFS
as a general whitespace delimiter.
.Pp
The results of substitution are, unless otherwise specified, also subject to
brace expansion and file name expansion (see the relevant sections below).
.Pp
A command substitution is replaced by the output generated by the specified
command which is run in a subshell.
For
.Pf $( Ns Ar command Ns \&)
and
.Pf ${\*(Ba\& Ns Ar command Ns \&;}
and
.Pf ${\ \& Ar command Ns \&;}
substitutions, normal quoting rules are used when
.Ar command
is parsed; however, for the deprecated
.Pf \` Ns Ar command Ns \`
form, a
.Ql \e
followed by any of
.Ql $ ,
.Ql \`
or
.Ql \e
is stripped (as is
.Ql \&"
when the substitution is part of a double-quoted string); a backslash
.Ql \e
followed by any other character is unchanged.
As a special case in command substitutions, a command of the form
.Pf \*(Lt Ar file
is interpreted to mean substitute the contents of
.Ar file .
Note that
.Ic $(\*(Ltfoo)
has the same effect as
.Ic $(cat foo) .
.Pp
Note that some shells do not use a recursive parser for command substitutions,
leading to failure for certain constructs; to be portable, use as workaround
.Dq Li x=$(cat) \*(Lt\*(Lt\eEOF
(or the newline-keeping
.Dq Li x=\*(Lt\*(Lt\eEOF
extension) instead to merely slurp the string.
.St -p1003.1
recommends using case statements of the form
.Li "x=$(case $foo in (bar) echo $bar ;; (*) echo $baz ;; esac)"
instead, which would work but not serve as example for this portability issue.
.Bd -literal -offset indent
x=$(case $foo in bar) echo $bar ;; *) echo $baz ;; esac)
# above fails to parse on old shells; below is the workaround
x=$(eval $(cat)) \*(Lt\*(Lt\eEOF
case $foo in bar) echo $bar ;; *) echo $baz ;; esac
EOF
.Ed
.Pp
Arithmetic substitutions are replaced by the value of the specified expression.
For example, the command
.Ic print $((2+3*4))
displays 14.
See
.Sx Arithmetic expressions
for a description of an expression.
.Ss Parameters
Parameters are shell variables; they can be assigned values and their values
can be accessed using a parameter substitution.
A parameter name is either one
of the special single punctuation or digit character parameters described
below, or a letter followed by zero or more letters or digits
.Po
.Ql _
counts as a letter
.Pc .
The latter form can be treated as arrays by appending an array index of the
form
.Op Ar expr
where
.Ar expr
is an arithmetic expression.
Array indices in
.Nm
are limited to the range 0 through 4294967295, inclusive.
That is, they are a 32-bit unsigned integer.
.Pp
Parameter substitutions take the form
.Pf $ Ns Ar name ,
.Pf ${ Ns Ar name Ns }
or
.Sm off
.Pf ${ Ar name Oo Ar expr Oc }
.Sm on
where
.Ar name
is a parameter name.
Substitutions of an an array in scalar context, i.e. without an
.Ar expr
in the latter form mentioned above, expand the element with the key
.Dq 0 .
Substitution of all array elements with
.Pf ${ Ns Ar name Ns \&[*]}
and
.Pf ${ Ns Ar name Ns \&[@]}
works equivalent to $* and $@ for positional parameters.
If substitution is performed on a parameter
(or an array parameter element)
that is not set, an empty string is substituted unless the
.Ic nounset
option
.Pq Ic set Fl u
is set, in which case an error occurs.
.Pp
Parameters can be assigned values in a number of ways.
First, the shell implicitly sets some parameters like
.Dq Li # ,
.Dq Li PWD
and
.Dq Li $ ;
this is the only way the special single character parameters are set.
Second, parameters are imported from the shell's environment at startup.
Third, parameters can be assigned values on the command line: for example,
.Ic FOO=bar
sets the parameter
.Dq Li FOO
to
.Dq Li bar ;
multiple parameter assignments can be given on a single command line and they
can be followed by a simple-command, in which case the assignments are in
effect only for the duration of the command (such assignments are also
exported; see below for the implications of this).
Note that both the parameter name and the
.Ql =
must be unquoted for the shell to recognise a parameter assignment.
The construct
.Ic FOO+=baz
is also recognised; the old and new values are immediately concatenated.
The fourth way of setting a parameter is with the
.Ic export ,
.Ic global ,
.Ic readonly
and
.Ic typeset
commands; see their descriptions in the
.Sx Command execution
section.
Fifth,
.Ic for
and
.Ic select
loops set parameters as well as the
.Ic getopts ,
.Ic read
and
.Ic set Fl A
commands.
Lastly, parameters can be assigned values using assignment operators
inside arithmetic expressions (see
.Sx Arithmetic expressions
below) or using the
.Sm off
.Pf ${ Ar name No = Ar value No }
.Sm on
form of the parameter substitution (see below).
.Pp
Parameters with the export attribute (set using the
.Ic export
or
.Ic typeset Fl x
commands, or by parameter assignments followed by simple commands) are put in
the environment (see
.Xr environ 7 )
of commands run by the shell as
.Ar name Ns = Ns Ar value
pairs.
The order in which parameters appear in the environment of a command is
unspecified.
When the shell starts up, it extracts parameters and their values
from its environment and automatically sets the export attribute for those
parameters.
.Pp
Modifiers can be applied to the
.Pf ${ Ns Ar name Ns }
form of parameter substitution:
.Bl -tag -width Ds
.Sm off
.It ${ Ar name No :\- Ar word No }
.Sm on
If
.Ar name
is set and not empty,
it is substituted; otherwise,
.Ar word
is substituted.
.Sm off
.It ${ Ar name No :+ Ar word No }
.Sm on
If
.Ar name
is set and not empty,
.Ar word
is substituted; otherwise, nothing is substituted.
.Sm off
.It ${ Ar name No := Ar word No }
.Sm on
If
.Ar name
is set and not empty,
it is substituted; otherwise, it is assigned
.Ar word
and the resulting value of
.Ar name
is substituted.
.Sm off
.It ${ Ar name No :? Ar word No }
.Sm on
If
.Ar name
is set and not empty,
it is substituted; otherwise,
.Ar word
is printed on standard error (preceded by
.Ar name : )
and an error occurs (normally causing termination of a shell script, function,
or a script sourced using the
.Dq Li \&.
built-in).
If
.Ar word
is omitted, the string
.Dq Li parameter null or not set
is used instead.
.El
.Pp
Note that, for all of the above,
.Ar word
is actually considered quoted, and special parsing rules apply.
The parsing rules also differ on whether the expression is double-quoted:
.Ar word
then uses double-quoting rules, except for the double quote itself
.Pq Ql \&"
and the closing brace, which, if backslash escaped, gets quote removal applied.
.Pp
In the above modifiers, the
.Ql \&:
can be omitted, in which case the conditions only depend on
.Ar name
being set (as opposed to set and not empty).
If
.Ar word
is needed, parameter, command, arithmetic and tilde substitution are performed
on it; if
.Ar word
is not needed, it is not evaluated.
.Pp
The following forms of parameter substitution can also be used:
.Pp
.Bl -tag -width Ds -compact
.It Pf ${# Ns Ar name Ns \&}
The number of positional parameters if
.Ar name
is
.Dq Li * ,
.Dq Li @
or not specified; otherwise the length
.Pq in characters
of the string value of parameter
.Ar name .
.Pp
.It Pf ${# Ns Ar name Ns \&[*]}
.It Pf ${# Ns Ar name Ns \&[@]}
The number of elements in the array
.Ar name .
.Pp
.It Pf ${% Ns Ar name Ns \&}
The width
.Pq in screen columns
of the string value of parameter
.Ar name ,
or \-1 if
.Pf ${ Ns Ar name Ns }
contains a control character.
.Pp
.It Pf ${! Ns Ar name Ns }
The name of the variable referred to by
.Ar name .
This will be
.Ar name
except when
.Ar name
is a name reference (bound variable), created by the
.Ic nameref
command (which is an alias for
.Ic typeset Fl n ) .
.Ar name
cannot be one of most special parameters (see below).
.Pp
.It Pf ${! Ns Ar name Ns \&[*]}
.It Pf ${! Ns Ar name Ns \&[@]}
The names of indices (keys) in the array
.Ar name .
.Pp
.Sm off
.It Xo
.Pf ${ Ar name
.Pf # Ar pattern No }
.Xc
.It Xo
.Pf ${ Ar name
.Pf ## Ar pattern No }
.Xc
.Sm on
If
.Ar pattern
matches the beginning of the value of parameter
.Ar name ,
the matched text is deleted from the result of substitution.
A single
.Ql #
results in the shortest match, and two
of them result in the longest match.
Cannot be applied to a vector
.Pq ${*} or ${@} or ${array[*]} or ${array[@]} .
.Pp
.Sm off
.It Xo
.Pf ${ Ar name
.Pf % Ar pattern No }
.Xc
.It Xo
.Pf ${ Ar name
.Pf %% Ar pattern No }
.Xc
.Sm on
Like ${...#...} substitution, but it deletes from the end of the value.
Cannot be applied to a vector.
.Pp
.Sm off
.It Xo
.Pf ${ Ar name
.Pf / Ar pattern / Ar string No }
.Xc
.It Xo
.Pf ${ Ar name
.Pf /# Ar pattern / Ar string No }
.Xc
.It Xo
.Pf ${ Ar name
.Pf /% Ar pattern / Ar string No }
.Xc
.It Xo
.Pf ${ Ar name
.Pf // Ar pattern / Ar string No }
.Xc
.Sm on
The longest match of
.Ar pattern
in the value of parameter
.Ar name
is replaced with
.Ar string
(deleted if
.Ar string
is empty; the trailing slash
.Pq Ql /
may be omitted in that case).
A leading slash followed by
.Ql #
or
.Ql %
causes the pattern to be anchored at the beginning or end of
the value, respectively; empty unanchored
.Ar pattern Ns s
cause no replacement; a single leading slash or use of a
.Ar pattern
that matches the empty string causes the replacement to
happen only once; two leading slashes cause all occurrences
of matches in the value to be replaced.
Cannot be applied to a vector.
Inefficiently implemented, may be slow.
.Pp
.Sm off
.It Xo
.Pf ${ Ar name
.Pf @/ Ar pattern / Ar string No }
.Xc
.Sm on
The same as
.Sm off
.Xo
.Pf ${ Ar name
.Pf // Ar pattern / Ar string No } ,
.Xc
.Sm on
except that both
.Ar pattern
and
.Ar string
are expanded anew for each iteration.
.Pp
.Sm off
.It Xo
.Pf ${ Ar name : Ns Ar pos
.Pf : Ns Ar len Ns }
.Xc
.Sm on
The first
.Ar len
characters of
.Ar name ,
starting at position
.Ar pos ,
are substituted.
Both
.Ar pos
and
.Pf : Ns Ar len
are optional.
If
.Ar pos
is negative, counting starts at the end of the string; if it
is omitted, it defaults to 0.
If
.Ar len
is omitted or greater than the length of the remaining string,
all of it is substituted.
Both
.Ar pos
and
.Ar len
are evaluated as arithmetic expressions.
Currently,
.Ar pos
must start with a space, opening parenthesis or digit to be recognised.
Cannot be applied to a vector.
.Pp
.It Pf ${ Ns Ar name Ns @#}
The hash (using the BAFH algorithm) of the expansion of
.Ar name .
This is also used internally for the shell's hashtables.
.Pp
.It Pf ${ Ns Ar name Ns @Q}
A quoted expression safe for re-entry, whose value is the value of the
.Ar name
parameter, is substituted.
.El
.Pp
Note that
.Ar pattern
may need extended globbing pattern
.Pq @(...) ,
single
.Pq \&\*(aq...\&\*(aq
or double
.Pq \&"...\&"
quote escaping unless
.Fl o Ic sh
is set.
.Pp
The following special parameters are implicitly set by the shell and cannot be
set directly using assignments:
.Bl -tag -width "1 .. 9"
.It Ev \&!
Process ID of the last background process started.
If no background processes have been started, the parameter is not set.
.It Ev \&#
The number of positional parameters ($1, $2, etc.).
.It Ev \&$
The PID of the shell or, if it is a subshell, the PID of the original shell.
Do
.Em NOT
use this mechanism for generating temporary file names; see
.Xr mktemp 1
instead.
.It Ev \-
The concatenation of the current single letter options (see the
.Ic set
command below for a list of options).
.It Ev \&?
The exit status of the last non-asynchronous command executed.
If the last command was killed by a signal,
.Ic \&$?
is set to 128 plus the signal number, but at most 255.
.It Ev 0
The name of the shell, determined as follows:
the first argument to
.Nm
if it was invoked with the
.Fl c
option and arguments were given; otherwise the
.Ar file
argument, if it was supplied;
or else the basename the shell was invoked with (i.e.\&
.Li argv[0] ) .
.Ev $0
is also set to the name of the current script or
the name of the current function, if it was defined with the
.Ic function
keyword (i.e. a Korn shell style function).
.It Ev 1 No .. Ev 9
The first nine positional parameters that were supplied to the shell, function,
or script sourced using the
.Dq Li \&.
built-in.
Further positional parameters may be accessed using
.Pf ${ Ar number Ns } .
.It Ev *
All positional parameters (except 0), i.e. $1, $2, $3, ...
.br
If used
outside of double quotes, parameters are separate words (which are subjected
to word splitting); if used within double quotes, parameters are separated
by the first character of the
.Ev IFS
parameter (or the empty string if
.Ev IFS
is unset.
.It Ev @
Same as
.Ic $* ,
unless it is used inside double quotes, in which case a separate word is
generated for each positional parameter.
If there are no positional parameters, no word is generated.
.Ic \&"$@"
can be used to access arguments, verbatim, without losing
empty arguments or splitting arguments with spaces (IFS, actually).
.El
.Pp
The following parameters are set and/or used by the shell:
.Bl -tag -width "KSH_VERSION"
.It Ev _
.Pq underscore
When an external command is executed by the shell, this parameter is set in the
environment of the new process to the path of the executed command.
In interactive use, this parameter is also set in the parent shell to the last
word of the previous command.
.It Ev BASHPID
The PID of the shell or subshell.
.It Ev CDPATH
Like
.Ev PATH ,
but used to resolve the argument to the
.Ic cd
built-in command.
Note that if
.Ev CDPATH
is set and does not contain
.Dq Li \&.
or an empty string element, the current directory is not searched.
Also, the
.Ic cd
built-in command will display the resulting directory when a match is found
in any search path other than the empty path.
.It Ev COLUMNS
Set to the number of columns on the terminal or window.
If never unset and not imported, always set dynamically;
unless the value as reported by
.Xr stty 1
is non-zero and sane enough (minimum is 12x3), defaults to 80; similar for
.Ev LINES .
This parameter is used by the interactive line editing modes and by the
.Ic select ,
.Ic set Fl o
and
.Ic kill Fl l
commands to format information columns.
Importing from the environment or unsetting this parameter removes the
binding to the actual terminal size in favour of the provided value.
.It Ev ENV
If this parameter is found to be set after any profile files are executed, the
expanded value is used as a shell startup file.
It typically contains function and alias definitions.
.It Ev EPOCHREALTIME
Time since the epoch, as returned by
.Xr gettimeofday 2 ,
formatted as decimal
.Va tv_sec
followed by a dot
.Pq Ql \&.
and
.Va tv_usec
padded to exactly six decimal digits.
.It Ev EXECSHELL
If set, this parameter is assumed to contain the shell that is to be used to
execute commands that
.Xr execve 2
fails to execute and which do not start with a
.Dq Li #! Ns Ar shell
sequence.
.It Ev FCEDIT
The editor used by the
.Ic fc
command (see below).
.It Ev FPATH
Like
.Ev PATH ,
but used when an undefined function is executed to locate the file defining the
function.
It is also searched when a command can't be found using
.Ev PATH .
See
.Sx Functions
below for more information.
.It Ev HISTFILE
The name of the file used to store command history.
When assigned to or unset, the file is opened, history is truncated
then loaded from the file; subsequent new commands (possibly consisting
of several lines) are appended once they successfully compiled.
Also, several invocations of the shell will share history if their
.Ev HISTFILE
parameters all point to the same file.
.Pp
.Sy Note :
If
.Ev HISTFILE
is unset or empty, no history file is used.
This is different from
.At
.Nm ksh .
.It Ev HISTSIZE
The number of commands normally stored for history.
The default is 2047.
Do not set this value to insanely high values such as 1000000000 because
.Nm
can then not allocate enough memory for the history and will not start.
.It Ev HOME
The default directory for the
.Ic cd
command and the value substituted for an unqualified
.Ic \*(TI
(see
.Sx Tilde expansion
below).
.It Ev IFS
Internal field separator, used during substitution and by the
.Ic read
command, to split values into distinct arguments; normally set to space, tab
and newline.
See
.Sx Substitution
above for details.
.Pp
.Sy Note :
This parameter is not imported from the environment when the shell is
started.
.It Ev KSHEGID
The effective group id of the shell.
.It Ev KSHGID
The real group id of the shell.
.It Ev KSHUID
The real user id of the shell.
.It Ev KSH_MATCH
The last matched string.
In a future version, this will be an indexed array,
with indexes 1 and up capturing matching groups.
Set by string comparisons (== and !=) in double-bracket test
expressions when a match is found (when != returns false), by
.Ic case
when a match is encountered, and by the substitution operations
.Sm off
.Xo
.Pf ${ Ar x
.Pf # Ar pat No } ,
.Sm on
.Xc
.Sm off
.Xo
.Pf ${ Ar x
.Pf ## Ar pat No } ,
.Sm on
.Xc
.Sm off
.Xo
.Pf ${ Ar x
.Pf % Ar pat No } ,
.Sm on
.Xc
.Sm off
.Xo
.Pf ${ Ar x
.Pf %% Ar pat No } ,
.Sm on
.Xc
.Sm off
.Xo
.Pf ${ Ar x
.Pf / Ar pat / Ar rpl No } ,
.Sm on
.Xc
.Sm off
.Xo
.Pf ${ Ar x
.Pf /# Ar pat / Ar rpl No } ,
.Sm on
.Xc
.Sm off
.Xo
.Pf ${ Ar x
.Pf /% Ar pat / Ar rpl No } ,
.Sm on
.Xc
.Sm off
.Xo
.Pf ${ Ar x
.Pf // Ar pat / Ar rpl No } ,
.Sm on
.Xc
and
.Sm off
.Xo
.Pf ${ Ar x
.Pf @/ Ar pat / Ar rpl No } .
.Sm on
.Xc
See the end of the Emacs editing mode documentation for an example.
.It Ev KSH_VERSION
The name and version of the shell (read-only).
See also the version commands in
.Sx Emacs editing mode
and
.Sx Vi editing mode
sections, below.
.It Ev LINENO
The line number of the function or shell script that is currently being
executed.
.It Ev LINES
Set to the number of lines on the terminal or window.
Defaults to 24; always set, unless imported or unset.
See
.Ev COLUMNS .
.It Ev OLDPWD
The previous working directory.
Unset if
.Ic cd
has not successfully changed directories since the shell started or if the
shell doesn't know where it is.
.It Ev OPTARG
When using
.Ic getopts ,
it contains the argument for a parsed option, if it requires one.
.It Ev OPTIND
The index of the next argument to be processed when using
.Ic getopts .
Assigning 1 to this parameter causes
.Ic getopts
to process arguments from the beginning the next time it is invoked.
.It Ev PATH
A colon (semicolon on OS/2) separated list of directories that are
searched when looking for commands and files sourced using the
.Dq Li \&.
command (see below).
An empty string resulting from a leading or trailing
(semi)colon, or two adjacent ones, is treated as a
.Dq Li \&.
(the current directory).
.It Ev PATHSEP
A colon (semicolon on OS/2), for the user's convenience.
.It Ev PGRP
The process ID of the shell's process group leader.
.It Ev PIPESTATUS
An array containing the errorlevel (exit status) codes,
one by one, of the last pipeline run in the foreground.
.It Ev PPID
The process ID of the shell's parent.
.It Ev PS1
The primary prompt for interactive shells.
Parameter, command and arithmetic
substitutions are performed, and
.Ql \&!
is replaced with the current command number (see the
.Ic fc
command below).
A literal
.Ql \&!
can be put in the prompt by placing
.Dq Li !!
in
.Ev PS1 .
.Pp
The default prompt is
.Dq Li $\ \&
for non-root users,
.Dq Li #\ \&
for root.
If
.Nm
is invoked by root and
.Ev PS1
does not contain a
.Ql #
character, the default value will be used even if
.Ev PS1
already exists in the environment.
.Pp
The
.Nm
distribution comes with a sample
.Pa dot.mkshrc
containing a sophisticated example, but you might like the following one
(note that ${HOSTNAME:=$(hostname)} and the
root-vs-user distinguishing clause are (in this example) executed at
.Ev PS1
assignment time, while the $USER and $PWD are escaped
and thus will be evaluated each time a prompt is displayed):
.Bd -literal
PS1=\*(aq${USER:=$(id \-un)}\*(aq"@${HOSTNAME:=$(hostname)}:\e$PWD $(
	if (( USER_ID )); then print \e$; else print \e#; fi) "
.Ed
.Pp
Note that since the command-line editors try to figure out how long the prompt
is (so they know how far it is to the edge of the screen), escape codes in
the prompt tend to mess things up.
You can tell the shell not to count certain
sequences (such as escape codes) by prefixing your prompt with a
character (such as Ctrl-A) followed by a carriage return and then delimiting
the escape codes with this character.
Any occurrences of that character in the prompt are not printed.
By the way, don't blame me for
this hack; it's derived from the original
.Xr ksh88 1 ,
which did print the delimiter character so you were out of luck
if you did not have any non-printing characters.
.Pp
Since backslashes and other special characters may be
interpreted by the shell, to set
.Ev PS1
either escape the backslash itself
or use double quotes.
The latter is more practical.
This is a more complex example,
avoiding to directly enter special characters (for example with
.Ic \*(haV
in the emacs editing mode),
which embeds the current working directory,
in reverse video
.Pq colour would work, too ,
in the prompt string:
.Bd -literal -offset indent
x=$(print \e\e001) # otherwise unused char
PS1="$x$(print \e\er)$x$(tput so)$x\e$PWD$x$(tput se)$x\*(Gt "
.Ed
.Pp
Due to a strong suggestion from David G. Korn,
.Nm
now also supports the following form:
.Bd -literal -offset indent
PS1=$\*(aq\e1\er\e1\ee[7m\e1$PWD\e1\ee[0m\e1\*(Gt \*(aq
.Ed
.It Ev PS2
Secondary prompt string, by default
.Dq Li \*(Gt\ \& ,
used when more input is needed to complete a command.
.It Ev PS3
Prompt used by the
.Ic select
statement when reading a menu selection.
The default is
.Dq Li #?\ \& .
.It Ev PS4
Used to prefix commands that are printed during execution tracing (see the
.Ic set Fl x
command below).
Parameter, command and arithmetic substitutions are performed
before it is printed.
The default is
.Dq Li +\ \& .
You may want to set it to
.Dq Li \&[$EPOCHREALTIME]\ \&
instead, to include timestamps.
.It Ev PWD
The current working directory.
May be unset or empty if the shell doesn't know where it is.
.It Ev RANDOM
Each time
.Ev RANDOM
is referenced, it is assigned a number between 0 and 32767 from
a Linear Congruential PRNG first.
.It Ev REPLY
Default parameter for the
.Ic read
command if no names are given.
Also used in
.Ic select
loops to store the value that is read from standard input.
.It Ev SECONDS
The number of seconds since the shell started or, if the parameter has been
assigned an integer value, the number of seconds since the assignment plus the
value that was assigned.
.It Ev TMOUT
If set to a positive integer in an interactive shell, it specifies the maximum
number of seconds the shell will wait for input after printing the primary
prompt
.Pq Ev PS1 .
If the time is exceeded, the shell exits.
.It Ev TMPDIR
The directory temporary shell files are created in.
If this parameter is not
set or does not contain the absolute path of a writable directory, temporary
files are created in
.Pa /tmp .
.It Ev USER_ID
The effective user id of the shell.
.El
.Ss Tilde expansion
Tilde expansion, which is done in parallel with parameter substitution,
is applied to words starting with an unquoted
.Ql \*(TI .
In parameter assignments (such as those preceding a simple-command or those
occurring in the arguments of a declaration utility), tilde expansion is done
after any assignment (i.e. after the equals sign) or after an unquoted colon
.Pq Ql \&: ;
login names are also delimited by colons.
The Korn shell, except in POSIX mode, always expands tildes after unquoted
equals signs, not just in assignment context (see below), and enables tab
completion for tildes after all unquoted colons during command line editing.
.Pp
The characters following the tilde, up to the first
.Ql / ,
if any, are assumed to be a login name.
If the login name is empty,
.Ql +
or
.Ql \- ,
the simplified value of the
.Ev HOME ,
.Ev PWD
or
.Ev OLDPWD
parameter is substituted, respectively.
Otherwise, the password file is
searched for the login name, and the tilde expression is substituted with the
user's home directory.
If the login name is not found in the password file or
if any quoting or parameter substitution occurs in the login name, no
substitution is performed.
.Pp
The home directory of previously expanded login names are cached and re-used.
The
.Ic alias Fl d
command may be used to list, change and add to this cache (e.g.\&
.Ic alias \-d fac=/usr/local/facilities; cd \*(TIfac/bin ) .
.Ss Brace expansion (alternation)
Brace expressions take the following form:
.Bd -unfilled -offset indent
.Sm off
.Xo
.Ar prefix No { Ar str1 No ,...,
.Ar strN No } Ar suffix
.Xc
.Sm on
.Ed
.Pp
The expressions are expanded to
.Ar N
words, each of which is the concatenation of
.Ar prefix ,
.Ar str Ns i
and
.Ar suffix
(e.g.\&
.Dq Li a{c,b{X,Y},d}e
expands to four words:
.Dq Li ace ,
.Dq Li abXe ,
.Dq Li abYe
and
.Dq Li ade ) .
As noted in the example, brace expressions can be nested and the resulting
words are not sorted.
Brace expressions must contain an unquoted comma
.Pq Ql \&,
for expansion to occur (e.g.\&
.Ic {}
and
.Ic {foo}
are not expanded).
Brace expansion is carried out after parameter substitution
and before file name generation.
.Ss File name patterns
A file name pattern is a word containing one or more unquoted
.Ql \&? ,
.Ql * ,
.Ql + ,
.Ql @
or
.Ql \&!
characters or
.Dq Li \&[...]
sequences.
Once brace expansion has been performed, the shell replaces file
name patterns with the sorted names of all the files that match the pattern
(if no files match, the word is left unchanged).
The pattern elements have the following meaning:
.Bl -tag -width Ds
.It \&?
Matches any single character.
.It \&*
Matches any sequence of octets.
.It \&[...]
Matches any of the octets inside the brackets.
Ranges of octets can be specified by separating two octets by a
.Ql \-
(e.g.\&
.Dq Li \&[a0\-9]
matches the letter
.Ql a
or any digit).
In order to represent itself, a
.Ql \-
must either be quoted or the first or last octet in the octet list.
Similarly, a
.Ql \&]
must be quoted or the first octet in the list if it is to represent itself
instead of the end of the list.
Also, a
.Ql \&!
appearing at the start of the list has special meaning (see below), so to
represent itself it must be quoted or appear later in the list.
.It \&[!...]
Like [...],
except it matches any octet not inside the brackets.
.Sm off
.It *( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
.Sm on
Matches any string of octets that matches zero or more occurrences of the
specified patterns.
Example: The pattern
.Ic *(foo\*(Babar)
matches the strings
.Dq ,
.Dq Li foo ,
.Dq Li bar ,
.Dq Li foobarfoo ,
etc.
.Sm off
.It +( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
.Sm on
Matches any string of octets that matches one or more occurrences of the
specified patterns.
Example: The pattern
.Ic +(foo\*(Babar)
matches the strings
.Dq Li foo ,
.Dq Li bar ,
.Dq Li foobar ,
etc.
.Sm off
.It ?( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
.Sm on
Matches the empty string or a string that matches one of the specified
patterns.
Example: The pattern
.Ic ?(foo\*(Babar)
only matches the strings
.Dq ,
.Dq Li foo
and
.Dq Li bar .
.Sm off
.It @( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
.Sm on
Matches a string that matches one of the specified patterns.
Example: The pattern
.Ic @(foo\*(Babar)
only matches the strings
.Dq Li foo
and
.Dq Li bar .
.Sm off
.It !( Ar pattern\*(Ba No ...\*(Ba Ar pattern )
.Sm on
Matches any string that does not match one of the specified patterns.
Examples: The pattern
.Ic !(foo\*(Babar)
matches all strings except
.Dq Li foo
and
.Dq Li bar ;
the pattern
.Ic \&!(*)
matches no strings; the pattern
.Ic \&!(?)*
matches all strings (think about it).
.El
.Pp
Note that complicated globbing, especially with alternatives,
is slow; using separate comparisons may (or may not) be faster.
.Pp
Note that
.Nm mksh
.Po and Nm pdksh Pc
never matches
.Dq Li \&.
and
.Dq Li .. ,
but
.At
.Nm ksh ,
Bourne
.Nm sh
and GNU
.Nm bash
do.
.Pp
Note that none of the above pattern elements match either a period
.Pq Ql \&.
at the start of a file name or a slash
.Pq Ql / ,
even if they are explicitly used in a [...] sequence; also, the names
.Dq Li \&.
and
.Dq Li ..
are never matched, even by the pattern
.Dq Li .* .
.Pp
If the
.Ic markdirs
option is set, any directories that result from file name generation are marked
with a trailing
.Ql / .
.Ss Input/output redirection
When a command is executed, its standard input, standard output and standard
error (file descriptors 0, 1 and 2, respectively) are normally inherited from
the shell.
Three exceptions to this are commands in pipelines, for which
standard input and/or standard output are those set up by the pipeline,
asynchronous commands created when job control is disabled, for which standard
input is initially set to
.Pa /dev/null ,
and commands for which any of the following redirections have been specified:
.Bl -tag -width XXxxmarker
.It \*(Gt Ns Ar file
Standard output is redirected to
.Ar file .
If
.Ar file
does not exist, it is created; if it does exist, is a regular file, and the
.Ic noclobber
option is set, an error occurs; otherwise, the file is truncated.
Note that this means the command
.Ic cmd \*(Ltfoo \*(Gtfoo
will open
.Ar foo
for reading and then truncate it when it opens it for writing, before
.Ar cmd
gets a chance to actually read
.Ar foo .
.It \*(Gt\*(Ba Ns Ar file
Same as
.Ic \*(Gt ,
except the file is truncated, even if the
.Ic noclobber
option is set.
.It \*(Gt\*(Gt Ns Ar file
Same as
.Ic \*(Gt ,
except if
.Ar file
exists it is appended to instead of being truncated.
Also, the file is opened
in append mode, so writes always go to the end of the file (see
.Xr open 2 ) .
.It \*(Lt Ns Ar file
Standard input is redirected from
.Ar file ,
which is opened for reading.
.It \*(Lt\*(Gt Ns Ar file
Same as
.Ic \*(Lt ,
except the file is opened for reading and writing.
.It \*(Lt\*(Lt Ns Ar marker
After reading the command line containing this kind of redirection (called a
.Dq here document ) ,
the shell copies lines from the command source into a temporary file until a
line matching
.Ar marker
is read.
When the command is executed, standard input is redirected from the
temporary file.
If
.Ar marker
contains no quoted characters, the contents of the temporary file are processed
as if enclosed in double quotes each time the command is executed, so
parameter, command and arithmetic substitutions are performed, along with
backslash
.Pq Ql \e
escapes for
.Ql $ ,
.Ql \` ,
.Ql \e
and
.Dq Li \enewline ,
but not for
.Ql \&" .
If multiple here documents are used on the same command line, they are saved in
order.
.Pp
If no
.Ar marker
is given, the here document ends at the next
.Ic \*(Lt\*(Lt
and substitution will be performed.
If
.Ar marker
is only a set of either single
.Dq Li \*(aq\*(aq
or double
.Ql \&""
quotes with nothing in between, the here document ends at the next empty line
and substitution will not be performed.
.It \*(Lt\*(Lt\- Ns Ar marker
Same as
.Ic \*(Lt\*(Lt ,
except leading tabs are stripped from lines in the here document.
.It \*(Lt\*(Lt\*(Lt Ns Ar word
Same as
.Ic \*(Lt\*(Lt ,
except that
.Ar word
.Em is
the here document.
This is called a here string.
.It \*(Lt& Ns Ar fd
Standard input is duplicated from file descriptor
.Ar fd .
.Ar fd
can be a single digit, indicating the number of an existing file descriptor;
the letter
.Ql p ,
indicating the file descriptor associated with the output of the current
co-process; or the character
.Ql \- ,
indicating standard input is to be closed.
.It \*(Gt& Ns Ar fd
Same as
.Ic \*(Lt& ,
except the operation is done on standard output.
.It &\*(Gt Ns Ar file
Same as
.Ic \*(Gt Ns Ar file 2\*(Gt&1 .
This is a deprecated (legacy) GNU
.Nm bash
extension supported by
.Nm
which also supports the preceding explicit fd digit, for example,
.Ic 3&\*(Gt Ns Ar file
is the same as
.Ic 3\*(Gt Ns Ar file 2\*(Gt&3
in
.Nm
but a syntax error in GNU
.Nm bash .
.It Xo
.No &\*(Gt\*(Ba Ns Ar file ,
.No &\*(Gt\*(Gt Ns Ar file ,
.No &\*(Gt& Ns Ar fd
.Xc
Same as
.Ic \*(Gt\*(Ba Ns Ar file ,
.Ic \*(Gt\*(Gt Ns Ar file
or
.Ic \*(Gt& Ns Ar fd ,
followed by
.Ic 2\*(Gt&1 ,
as above.
These are
.Nm
extensions.
.El
.Pp
In any of the above redirections, the file descriptor that is redirected
(i.e. standard input or standard output)
can be explicitly given by preceding the
redirection with a single digit.
Parameter, command and arithmetic
substitutions, tilde substitutions, and, if the shell is interactive,
file name generation are all performed on the
.Ar file ,
.Ar marker
and
.Ar fd
arguments of redirections.
Note, however, that the results of any file name
generation are only used if a single file is matched; if multiple files match,
the word with the expanded file name generation characters is used.
Note
that in restricted shells, redirections which can create files cannot be used.
.Pp
For simple-commands, redirections may appear anywhere in the command; for
compound-commands
.Po
.Ic if
statements, etc.
.Pc ,
any redirections must appear at the end.
Redirections are processed after
pipelines are created and in the order they are given, so the following
will print an error with a line number prepended to it:
.Pp
.Dl $ cat /foo/bar 2\*(Gt&1 \*(Gt/dev/null \*(Ba pr \-n \-t
.Pp
File descriptors created by I/O redirections are private to the shell.
.Ss Arithmetic expressions
Integer arithmetic expressions can be used with the
.Ic let
command, inside $((...)) expressions, inside array references (e.g.\&
.Ar name Ns Bq Ar expr ) ,
as numeric arguments to the
.Ic test
command, and as the value of an assignment to an integer parameter.
.Em Warning :
This also affects implicit conversion to integer, for example as done by the
.Ic let
command.
.Em Never
use unchecked user input, e.g. from the environment, in an arithmetic context!
.Pp
Expressions are calculated using signed arithmetic and the
.Vt mksh_ari_t
type (a 32-bit signed integer), unless they begin with a sole
.Ql #
character, in which case they use
.Vt mksh_uari_t
.Po a 32-bit unsigned integer Pc .
.Pp
Expressions may contain alpha-numeric parameter identifiers, array references
and integer constants and may be combined with the following C operators
(listed and grouped in increasing order of precedence):
.Pp
Unary operators:
.Bd -literal -offset indent
+ \- ! \*(TI ++ \-\-
.Ed
.Pp
Binary operators:
.Bd -literal -offset indent
,
= += \-= *= /= %= \*(Lt\*(Lt= \*(Gt\*(Gt= \*(ha\*(Lt= \*(ha\*(Gt= &= \*(ha= \*(Ba=
\*(Ba\*(Ba
&&
\*(Ba
\*(ha
&
== !=
\*(Lt \*(Lt= \*(Gt \*(Gt=
\*(Lt\*(Lt \*(Gt\*(Gt \*(ha\*(Lt \*(ha\*(Gt
+ \-
* / %
.Ed
.Pp
Ternary operators:
.Bd -literal -offset indent
?: (precedence is immediately higher than assignment)
.Ed
.Pp
Grouping operators:
.Bd -literal -offset indent
( )
.Ed
.Pp
Integer constants and expressions are calculated using an exactly 32-bit
wide, signed or unsigned, type with silent wraparound on integer overflow.
Integer constants may be specified with arbitrary bases using the notation
.Ar base Ns # Ns Ar number ,
where
.Ar base
is a decimal integer specifying the base (up to 36), and
.Ar number
is a number in the specified base.
Additionally, base-16 integers may be specified by prefixing them with
.Dq Li 0x
.Pq case-insensitive
in all forms of arithmetic expressions, except as numeric arguments to the
.Ic test
built-in utility.
Prefixing numbers with a sole digit zero
.Pq Dq Li 0
does not cause interpretation as octal (except in POSIX mode,
as required by the standard), as that's unsafe to do.
.Pp
As a special
.Nm mksh
extension, numbers to the base of one are treated as either (8-bit
transparent) ASCII or Universal Coded Character Set codepoints,
depending on the shell's
.Ic utf8\-mode
flag (current setting).
The
.At
.Nm ksh93
syntax of
.Dq Li \*(aqx\*(aq
instead of
.Dq Li 1#x
is also supported.
Note that NUL bytes (integral value of zero) cannot be used.
An unset or empty parameter evaluates to 0 in integer context.
In UTF-8 mode, raw octets are mapped into the range EF80..EFFF as in
OPTU-8, which is in the PUA and has been assigned by CSUR for this use.
If more than one octet in ASCII mode, or a sequence of more than one
octet not forming a valid and minimal CESU-8 sequence is passed, the
behaviour is undefined (usually, the shell aborts with a parse error,
but rarely, it succeeds, e.g. on the sequence C2 20).
That's why you should always use ASCII mode unless you know that the
input is well-formed UTF-8 in the range of 0000..FFFD if you use this
feature, as opposed to
.Ic read Fl a .
.Pp
The operators are evaluated as follows:
.Bl -tag -width Ds -offset indent
.It unary +
Result is the argument (included for completeness).
.It unary \-
Negation.
.It \&!
Logical NOT;
the result is 1 if argument is zero, 0 if not.
.It \*(TI
Arithmetic (bit-wise) NOT.
.It ++
Increment; must be applied to a parameter (not a literal or other expression).
The parameter is incremented by 1.
When used as a prefix operator, the result
is the incremented value of the parameter; when used as a postfix operator, the
result is the original value of the parameter.
.It \-\-
Similar to
.Ic ++ ,
except the parameter is decremented by 1.
.It \&,
Separates two arithmetic expressions; the left-hand side is evaluated first,
then the right.
The result is the value of the expression on the right-hand side.
.It =
Assignment; the variable on the left is set to the value on the right.
.It Xo
.No += \-= *= /= %= \*(Lt\*(Lt= \*(Gt\*(Gt=
.No \*(ha\*(Lt= \*(ha\*(Gt= &= \*(ha= \*(Ba=
.Xc
Assignment operators.
.Sm off
.Ao Ar var Ac Xo
.Aq Ar op
.No = Aq Ar expr
.Xc
.Sm on
is the same as
.Sm off
.Ao Ar var Ac Xo
.No = Aq Ar var
.Aq Ar op
.Aq Ar expr ,
.Xc
.Sm on
with any operator precedence in
.Aq Ar expr
preserved.
For example,
.Dq Li var1 *= 5 + 3
is the same as specifying
.Dq Li var1 = var1 * (5 + 3) .
.It \*(Ba\*(Ba
Logical OR;
the result is 1 if either argument is non-zero, 0 if not.
The right argument is evaluated only if the left argument is zero.
.It &&
Logical AND;
the result is 1 if both arguments are non-zero, 0 if not.
The right argument is evaluated only if the left argument is non-zero.
.It \*(Ba
Arithmetic (bit-wise) OR.
.It \*(ha
Arithmetic (bit-wise) XOR
(exclusive-OR).
.It &
Arithmetic (bit-wise) AND.
.It ==
Equal; the result is 1 if both arguments are equal, 0 if not.
.It !=
Not equal; the result is 0 if both arguments are equal, 1 if not.
.It \*(Lt
Less than; the result is 1 if the left argument is less than the right, 0 if
not.
.It \*(Lt= \*(Gt \*(Gt=
Less than or equal, greater than, greater than or equal.
See
.Ic \*(Lt .
.It \*(Lt\*(Lt \*(Gt\*(Gt
Shift left (right); the result is the left argument with its bits
arithmetically (signed operation) or logically (unsigned expression)
shifted left (right) by the amount given in the right argument.
.It \*(ha\*(Lt \*(ha\*(Gt
Rotate left (right); the result is similar to shift,
except that the bits shifted out at one end are shifted in
at the other end, instead of zero or sign bits.
.It + \- * /
Addition, subtraction, multiplication and division.
.It %
Remainder; the result is the symmetric remainder of the division of the left
argument by the right.
To get the mathematical modulus of
.Dq a Ic mod No b ,
use the formula
.Do
.Pq a % b + b
.No % b
.Dc .
.It Xo
.Sm off
.Aq Ar arg1 ?
.Aq Ar arg2 :
.Aq Ar arg3
.Sm on
.Xc
If
.Aq Ar arg1
is non-zero, the result is
.Aq Ar arg2 ;
otherwise the result is
.Aq Ar arg3 .
The non-result argument is not evaluated.
.El
.Ss Co-processes
A co-process (which is a pipeline created with the
.Dq Li \*(Ba&
operator) is an asynchronous process that the shell can both write to (using
.Ic print Fl p )
and read from (using
.Ic read Fl p ) .
The input and output of the co-process can also be manipulated using
.Ic \*(Gt&p
and
.Ic \*(Lt&p
redirections, respectively.
Once a co-process has been started, another can't
be started until the co-process exits, or until the co-process's input has been
redirected using an
.Ic exec Ar n Ns Ic \*(Gt&p
redirection.
If a co-process's input is redirected in this way, the next
co-process to be started will share the output with the first co-process,
unless the output of the initial co-process has been redirected using an
.Ic exec Ar n Ns Ic \*(Lt&p
redirection.
.Pp
Some notes concerning co-processes:
.Bl -bullet
.It
The only way to close the co-process's input (so the co-process reads an
end-of-file) is to redirect the input to a numbered file descriptor and then
close that file descriptor:
.Ic exec 3\*(Gt&p; exec 3\*(Gt&\-
.It
In order for co-processes to share a common output, the shell must keep the
write portion of the output pipe open.
This means that end-of-file will not be
detected until all co-processes sharing the co-process's output have exited
(when they all exit, the shell closes its copy of the pipe).
This can be
avoided by redirecting the output to a numbered file descriptor (as this also
causes the shell to close its copy).
Note that this behaviour is slightly
different from the original Korn shell which closes its copy of the write
portion of the co-process output when the most recently started co-process
(instead of when all sharing co-processes) exits.
.It
.Ic print Fl p
will ignore
.Dv SIGPIPE
signals during writes if the signal is not being trapped or ignored; the same
is true if the co-process input has been duplicated to another file descriptor
and
.Ic print Fl u Ns Ar n
is used.
.El
.Ss Functions
Functions are defined using either Korn shell
.Ic function Ar function-name
syntax or the Bourne/POSIX shell
.Ar function-name Ns \&()
syntax (see below for the difference between the two forms).
Functions are like
.Li .\(hyscripts
(i.e. scripts sourced using the
.Dq Li \&.
built-in)
in that they are executed in the current environment.
However, unlike
.Li .\(hyscripts ,
shell arguments (i.e. positional parameters $1, $2, etc.)\&
are never visible inside them.
When the shell is determining the location of a command, functions
are searched after special built-in commands, before builtins and the
.Ev PATH
is searched.
.Pp
An existing function may be deleted using
.Ic unset Fl f Ar function-name .
A list of functions can be obtained using
.Ic typeset +f
and the function definitions can be listed using
.Ic typeset Fl f .
The
.Ic autoload
command (which is an alias for
.Ic typeset Fl fu )
may be used to create undefined functions: when an undefined function is
executed, the shell searches the path specified in the
.Ev FPATH
parameter for a file with the same name as the function which, if found, is
read and executed.
If after executing the file the named function is found to
be defined, the function is executed; otherwise, the normal command search is
continued (i.e. the shell searches the regular built-in command table and
.Ev PATH ) .
Note that if a command is not found using
.Ev PATH ,
an attempt is made to autoload a function using
.Ev FPATH
(this is an undocumented feature of the original Korn shell).
.Pp
Functions can have two attributes,
.Dq trace
and
.Dq export ,
which can be set with
.Ic typeset Fl ft
and
.Ic typeset Fl fx ,
respectively.
When a traced function is executed, the shell's
.Ic xtrace
option is turned on for the function's duration.
The
.Dq export
attribute of functions is currently not used.
.Pp
Since functions are executed in the current shell environment, parameter
assignments made inside functions are visible after the function completes.
If this is not the desired effect, the
.Ic typeset
command can be used inside a function to create a local parameter.
Note that
.At
.Nm ksh93
uses static scoping (one global scope, one local scope per function)
and allows local variables only on Korn style functions, whereas
.Nm mksh
uses dynamic scoping (nested scopes of varying locality).
Note that special parameters (e.g.\&
.Ic \&$$ , $! )
can't be scoped in this way.
.Pp
The exit status of a function is that of the last command executed in the
function.
A function can be made to finish immediately using the
.Ic return
command; this may also be used to explicitly specify the exit status.
Note that when called in a subshell,
.Ic return
will only exit that subshell and will not cause the original shell to exit
a running function (see the
.Ic while Ns Li \&... Ns Ic read
loop FAQ below).
.Pp
Functions defined with the
.Ic function
reserved word are treated differently in the following ways from functions
defined with the
.Ic \&()
notation:
.Bl -bullet
.It
The $0 parameter is set to the name of the function
(Bourne-style functions leave $0 untouched).
.It
Parameter assignments preceding function calls are not kept in the shell
environment (executing Bourne-style functions will keep assignments).
.It
.Ev OPTIND
is saved/reset and restored on entry and exit from the function so
.Ic getopts
can be used properly both inside and outside the function (Bourne-style
functions leave
.Ev OPTIND
untouched, so using
.Ic getopts
inside a function interferes with using
.Ic getopts
outside the function).
.It
Shell options
.Pq Ic set Fl o
have local scope, i.e. changes inside a function are reset upon its exit.
.El
.Pp
In the future, the following differences may also be added:
.Bl -bullet
.It
A separate trap/signal environment will be used during the execution of
functions.
This will mean that traps set inside a function will not affect the
shell's traps and signals that are not ignored in the shell (but may be
trapped) will have their default effect in a function.
.It
The EXIT trap, if set in a function, will be executed after the function
returns.
.El
.Ss Command execution
After evaluation of command-line arguments, redirections and parameter
assignments, the type of command is determined: a special built-in command,
a function, a normal builtin or the name of a file to execute found using the
.Ev PATH
parameter.
The checks are made in the above order.
Special built-in commands differ from other commands in that the
.Ev PATH
parameter is not used to find them, an error during their execution can
cause a non-interactive shell to exit, and parameter assignments that are
specified before the command are kept after the command completes.
Regular built-in commands are different only in that the
.Ev PATH
parameter is not used to find them.
.Pp
The original
.Nm ksh
and POSIX differ somewhat in which commands are considered
special or regular.
.Pp
POSIX special built-in utilities:
.Pp
.Ic \&. , \&: , break , continue ,
.Ic eval , exec , exit , export ,
.Ic readonly , return , set , shift ,
.Ic times , trap , unset
.Pp
Additional
.Nm
commands keeping assignments:
.Pp
.Ic global , source , typeset
.Pp
Builtins that are not special:
.Pp
.Ic [ , alias , bg , bind ,
.Ic builtin , cat , cd , command ,
.Ic echo , false , fc , fg ,
.Ic getopts , jobs , kill , let ,
.Ic print , pwd , read , realpath ,
.Ic rename , sleep , suspend , test ,
.Ic true , ulimit , umask , unalias ,
.Ic wait , whence
.Pp
Once the type of command has been determined, any command-line parameter
assignments are performed and exported for the duration of the command.
.Pp
The following describes the special and regular built-in commands and
builtin-like reserved words:
.Pp
.Bl -tag -width false -compact
.It Ic \&. Ar file Op Ar arg ...
This is called the
.Dq dot
command.
Execute the commands in
.Ar file
in the current environment.
The file is searched for in the directories of
.Ev PATH .
If arguments are given, the positional parameters may be used to access them
while
.Ar file
is being executed.
If no arguments are given, the positional parameters are
those of the environment the command is used in.
.Pp
.It Ic \&: Op Ar ...
The null command.
Exit status is set to zero.
.Pp
.It Ic \&[ Ar expression Ic \&]
See
.Ic test .
.Pp
.It Xo Ic alias
.Oo Fl d \*(Ba t Oo Fl r Oc \*(Ba
.Cm +\-x Oc
.Op Fl p
.Op Cm +
.Oo Ar name
.Op Ns = Ns Ar value
.Ar ... Oc
.Xc
Without arguments,
.Ic alias
lists all aliases.
For any name without a value, the existing alias is listed.
Any name with a value defines an alias; see
.Sx Aliases
above.
.Li \&[][A\-Za\-z0\-9_!%,.@:\-]
are valid in names, except they may not begin with a hyphen-minus, and
.Ic \&[[
is not a valid alias name.
.Pp
When listing aliases, one of two formats is used.
Normally, aliases are listed as
.Ar name Ns = Ns Ar value ,
where
.Ar value
is quoted.
If options were preceded with
.Ql + ,
or a lone
.Ql +
is given on the command line, only
.Ar name
is printed.
.Pp
The
.Fl d
option causes directory aliases which are used in tilde expansion to be
listed or set (see
.Sx Tilde expansion
above).
.Pp
If the
.Fl p
option is used, each alias is prefixed with the string
.Dq Li alias\ \& .
.Pp
The
.Fl t
option indicates that tracked aliases are to be listed/set (values specified on
the command line are ignored for tracked aliases).
The
.Fl r
option indicates that all tracked aliases are to be reset.
.Pp
The
.Fl x
option sets
.Pq Ic +x No clears
the export attribute of an alias, or, if no names are given, lists the aliases
with the export attribute (exporting an alias has no effect).
.Pp
.It Ic bg Op Ar job ...
Resume the specified stopped job(s) in the background.
If no jobs are specified,
.Ic %+
is assumed.
See
.Sx Job control
below for more information.
.Pp
.It Ic bind Op Fl l
The current bindings are listed.
If the
.Fl l
flag is given,
.Ic bind
instead lists the names of the functions to which keys may be bound.
See
.Sx Emacs editing mode
for more information.
.Pp
.It Xo Ic bind Op Fl m
.Ar string Ns = Ns Op Ar substitute
.Ar ...
.Xc
.It Xo Ic bind
.Ar string Ns = Ns Op Ar editing-command
.Ar ...
.Xc
The specified editing command is bound to the given
.Ar string ,
which should consist of a control character
optionally preceded by one of the two prefix characters
and optionally succeeded by a tilde character.
Future input of the
.Ar string
will cause the editing command to be immediately invoked.
If the
.Fl m
flag is given, the specified input
.Ar string
will afterwards be immediately replaced by the given
.Ar substitute
string which may contain editing commands but not other macros.
If a tilde postfix is given, a tilde trailing the one or
two prefices and the control character is ignored, any
other trailing character will be processed afterwards.
.Pp
Control characters may be written using caret notation
i.e. \*(haX represents Ctrl-X.
The caret itself can be escaped by a backslash, which also escapes itself.
Note that although only three prefix characters (usually ESC, \*(haX and NUL)
are supported, some multi-character sequences can be supported.
.Pp
The following default bindings show how the arrow keys, the home, end and
delete key on a BSD wsvt25, xterm\-xfree86 or GNU screen terminal are bound
(of course some escape sequences won't work out quite this nicely):
.Bd -literal -offset indent
bind \*(aq\*(haX\*(aq=prefix\-2
bind \*(aq\*(ha[[\*(aq=prefix\-2
bind \*(aq\*(haXA\*(aq=up\-history
bind \*(aq\*(haXB\*(aq=down\-history
bind \*(aq\*(haXC\*(aq=forward\-char
bind \*(aq\*(haXD\*(aq=backward\-char
bind \*(aq\*(haX1\*(TI\*(aq=beginning\-of\-line
bind \*(aq\*(haX7\*(TI\*(aq=beginning\-of\-line
bind \*(aq\*(haXH\*(aq=beginning\-of\-line
bind \*(aq\*(haX4\*(TI\*(aq=end\-of\-line
bind \*(aq\*(haX8\*(TI\*(aq=end\-of\-line
bind \*(aq\*(haXF\*(aq=end\-of\-line
bind \*(aq\*(haX3\*(TI\*(aq=delete\-char\-forward
.Ed
.Pp
.It Ic break Op Ar level
Exit the
.Ar level Ns th
inner-most
.Ic for ,
.Ic select ,
.Ic until
or
.Ic while
loop.
.Ar level
defaults to 1.
.Pp
.It Xo
.Ic builtin
.Op Fl \-
.Ar command Op Ar arg ...
.Xc
Execute the built-in command
.Ar command .
.Pp
.It Xo
.Ic \ebuiltin
.Ar command Op Ar arg ...
.Xc
Same as
.Ic builtin .
Additionally acts as declaration utility forwarder, i.e. this is a
declaration utility (see
.Sx Tilde expansion )
.No iff Ar command
is a declaration utility.
.Pp
.It Xo
.Ic cat
.Op Fl u
.Op Ar
.Xc
Read files sequentially, in command line order, and write them to
standard output.
If a
.Ar file
is a single dash
.Pq Dq Li \-
or absent, read from standard input.
For direct builtin calls, the
.Tn POSIX
.Fl u
option is supported as a no-op.
For calls from shell, if any options are given, an external
.Xr cat 1
utility is preferred over the builtin.
.Pp
.It Xo
.Ic cd
.Op Fl L
.Op Ar dir
.Xc
.It Xo
.Ic cd
.Fl P Op Fl e
.Op Ar dir
.Xc
.It Xo
.Ic chdir
.Op Fl eLP
.Op Ar dir
.Xc
Set the working directory to
.Ar dir .
If the parameter
.Ev CDPATH
is set, it lists the search path for the directory containing
.Ar dir .
An unset or empty path means the current directory.
If
.Ar dir
is found in any component of the
.Ev CDPATH
search path other than an unset or empty path,
the name of the new working directory will be written to standard output.
If
.Ar dir
is missing, the home directory
.Ev HOME
is used.
If
.Ar dir
is
.Dq Li \- ,
the previous working directory is used (see the
.Ev OLDPWD
parameter).
.Pp
If the
.Fl L
option (logical path) is used or if the
.Ic physical
option isn't set (see the
.Ic set
command below), references to
.Dq Li ..
in
.Ar dir
are relative to the path used to get to the directory.
If the
.Fl P
option (physical path) is used or if the
.Ic physical
option is set,
.Dq Li ..
is relative to the filesystem directory tree.
The
.Ev PWD
and
.Ev OLDPWD
parameters are updated to reflect the current and old working directory,
respectively.
If the
.Fl e
option is set for physical filesystem traversal and
.Ev PWD
could not be set, the exit code is 1; greater than 1 if an
error occurred, 0 otherwise.
.Pp
.It Xo
.Ic cd
.Op Fl eLP
.Ar old new
.Xc
.It Xo
.Ic chdir
.Op Fl eLP
.Ar old new
.Xc
The string
.Ar new
is substituted for
.Ar old
in the current directory, and the shell attempts to change to the new
directory.
.Pp
.It Xo
.Ic command
.Op Fl pVv
.Ar cmd
.Op Ar arg ...
.Xc
If neither the
.Fl v
nor
.Fl V
option is given,
.Ar cmd
is executed exactly as if
.Ic command
had not been specified, with two exceptions:
firstly,
.Ar cmd
cannot be a shell function;
and secondly, special built-in commands lose their specialness
(i.e. redirection and utility errors do not cause the shell to
exit, and command assignments are not permanent).
The declaration utility property is not reset.
.Pp
If the
.Fl p
option is given, a default search path is used instead of the current value of
.Ev PATH ,
the actual value of which is system dependent.
.Pp
If the
.Fl v
option is given, instead of executing
.Ar cmd ,
information about what would be executed is given (and the same is done for
.Ar arg ... ) .
For builtins, functions and keywords, their names are simply printed;
for aliases, a command that defines them is printed;
for utilities found by searching the
.Ev PATH
parameter, the full path of the command is printed.
If no command is found
(i.e. the path search fails), nothing is printed and
.Ic command
exits with a non-zero status.
The
.Fl V
option is like the
.Fl v
option, except it is more verbose.
.Pp
.It Ic continue Op Ar level
Jumps to the beginning of the
.Ar level Ns th
inner-most
.Ic for ,
.Ic select ,
.Ic until
or
.Ic while
loop.
.Ar level
defaults to 1.
.Pp
.It Xo
.Ic echo
.Op Fl Een
.Op Ar arg ...
.Xc
.Em Warning:
this utility is not portable; use the Korn shell builtin
.Ic print
instead.
.Pp
Prints its arguments (separated by spaces) followed by a newline, to the
standard output.
The newline is suppressed if any of the arguments contain the
backslash sequence
.Dq Li \ec .
See the
.Ic print
command below for a list of other backslash sequences that are recognised.
.Pp
The options are provided for compatibility with
.Bx
shell scripts.
The
.Fl n
option suppresses the trailing newline,
.Fl e
enables backslash interpretation (a no-op, since this is normally done), and
.Fl E
suppresses backslash interpretation.
.Pp
If the
.Ic posix
or
.Ic sh
option is set or this is a direct builtin call or
.Ic print
.Fl R ,
only the first argument is treated as an option, and only if it is exactly
.Dq Li \-n .
Backslash interpretation is disabled.
.Pp
.It Ic eval Ar command ...
The arguments are concatenated (with spaces between them) to form a single
string which the shell then parses and executes in the current environment.
.Pp
.It Xo
.Ic exec
.Op Fl a Ar argv0
.Op Fl c
.Op Ar command Op Ar arg ...
.Xc
The command is executed without forking, replacing the shell process.
This is currently absolute, i.e.\&
.Ic exec
never returns, even if the
.Ar command
is not found.
The
.Fl a
option permits setting a different
.Li argv[0]
value, and
.Fl c
clears the environment before executing the child process, except for the
.Ev _
variable and direct assignments.
.Pp
If no command is given except for I/O redirection, the I/O redirection is
permanent and the shell is
not replaced.
Any file descriptors greater than 2 which are opened or
.Xr dup 2 Ns 'd
in this way are not made available to other executed commands (i.e. commands
that are not built-in to the shell).
Note that the Bourne shell differs here;
it does pass these file descriptors on.
.Pp
.It Ic exit Op Ar status
The shell or subshell exits with the specified exit status.
If
.Ar status
is not specified, the exit status is the current value of the
.Ic \&$?
parameter.
.Pp
.It Xo
.Ic export
.Op Fl p
.Op Ar parameter Ns Op = Ns Ar value
.Xc
Sets the export attribute of the named parameters.
Exported parameters are passed in the environment to executed commands.
If values are specified, the named parameters are also assigned.
This is a declaration utility.
.Pp
If no parameters are specified, all parameters with the export attribute
set are printed one per line; either their names, or, if a
.Dq Li \-
with no option letter is specified, name=value pairs, or, with
.Fl p ,
.Ic export
commands suitable for re-entry.
.Pp
.It Ic false
A command that exits with a non-zero status.
.Pp
.It Xo
.Ic fc
.Oo Fl e Ar editor \*(Ba
.Fl l Op Fl n Oc
.Op Fl r
.Op Ar first Op Ar last
.Xc
.Ar first
and
.Ar last
select commands from the history.
Commands can be selected by history number
(negative numbers go backwards from the current, most recent, line)
or a string specifying the most recent command starting with that string.
The
.Fl l
option lists the command on standard output, and
.Fl n
inhibits the default command numbers.
The
.Fl r
option reverses the order of the list.
Without
.Fl l ,
the selected commands are edited by the editor specified with the
.Fl e
option or, if no
.Fl e
is specified, the editor specified by the
.Ev FCEDIT
parameter (if this parameter is not set,
.Pa /bin/ed
is used), and then executed by the shell.
.Pp
.It Xo
.Ic fc
.Cm \-e \- \*(Ba Fl s
.Op Fl g
.Op Ar old Ns = Ns Ar new
.Op Ar prefix
.Xc
Re-execute the selected command (the previous command by default) after
performing the optional substitution of
.Ar old
with
.Ar new .
If
.Fl g
is specified, all occurrences of
.Ar old
are replaced with
.Ar new .
The meaning of
.Cm \-e \-
and
.Fl s
is identical: re-execute the selected command without invoking an editor.
This command is usually accessed with the predefined:
.Ic alias r=\*(aqfc \-e \-\*(aq
.Pp
.It Ic fg Op Ar job ...
Resume the specified job(s) in the foreground.
If no jobs are specified,
.Ic %+
is assumed.
See
.Sx Job control
below for more information.
.Pp
.It Xo
.Ic getopts
.Ar optstring name
.Op Ar arg ...
.Xc
Used by shell procedures to parse the specified arguments (or positional
parameters, if no arguments are given) and to check for legal options.
.Ar optstring
contains the option letters that
.Ic getopts
is to recognise.
If a letter is followed by a colon, the option is expected to
have an argument.
Options that do not take arguments may be grouped in a single argument.
If an option takes an argument and the option character is not the
last character of the argument it is found in, the remainder of the argument is
taken to be the option's argument; otherwise, the next argument is the option's
argument.
.Pp
Each time
.Ic getopts
is invoked, it places the next option in the shell parameter
.Ar name
and the index of the argument to be processed by the next call to
.Ic getopts
in the shell parameter
.Ev OPTIND .
If the option was introduced with a
.Ql + ,
the option placed in
.Ar name
is prefixed with a
.Ql + .
When an option requires an argument,
.Ic getopts
places it in the shell parameter
.Ev OPTARG .
.Pp
When an illegal option or a missing option argument is encountered, a question
mark or a colon is placed in
.Ar name
(indicating an illegal option or missing argument, respectively) and
.Ev OPTARG
is set to the option character that caused the problem.
Furthermore, if
.Ar optstring
does not begin with a colon, a question mark is placed in
.Ar name ,
.Ev OPTARG
is unset, and an error message is printed to standard error.
.Pp
When the end of the options is encountered,
.Ic getopts
exits with a non-zero exit status.
Options end at the first (non-option
argument) argument that does not start with a
.Ql \- ,
or when a
.Dq Li \-\-
argument is encountered.
.Pp
Option parsing can be reset by setting
.Ev OPTIND
to 1 (this is done automatically whenever the shell or a shell procedure is
invoked).
.Pp
Warning: Changing the value of the shell parameter
.Ev OPTIND
to a value other than 1 or parsing different sets of arguments without
resetting
.Ev OPTIND
may lead to unexpected results.
.Pp
.It Xo
.Ic global
.Op Ic +\-aglpnrtUux
.Oo Fl L Ns Op Ar n
.No \*(Ba Fl R Ns Op Ar n
.No \*(Ba Fl Z Ns Op Ar n Oc
.Op Fl i Ns Op Ar n
.Oo Ar name
.Op Ns = Ns Ar value
.Ar ... Oc
.Xc
See
.Ic typeset Fl g .
.No Deprecated , Em will
be removed from a future version of
.Nm .
.Pp
.It Xo
.Ic hash
.Op Fl r
.Op Ar name ...
.Xc
Without arguments, any hashed executable command pathnames are listed.
The
.Fl r
option causes all hashed commands to be removed from the hash table.
Each
.Ar name
is searched as if it were a command name and added to the hash table if it is
an executable command.
.Pp
.It Xo
.Ic jobs
.Op Fl lnp
.Op Ar job ...
.Xc
Display information about the specified job(s); if no jobs are specified, all
jobs are displayed.
The
.Fl n
option causes information to be displayed only for jobs that have changed
state since the last notification.
If the
.Fl l
option is used, the process ID of each process in a job is also listed.
The
.Fl p
option causes only the process group of each job to be printed.
See
.Sx Job control
below for the format of
.Ar job
and the displayed job.
.Pp
.It Xo
.Ic kill
.Oo Fl s Ar signame \*(Ba
.No \- Ns Ar signum \*(Ba
.No \- Ns Ar signame Oc
.No { Ar job \*(Ba pid \*(Ba pgrp No }
.Ar ...
.Xc
Send the specified signal to the specified jobs, process IDs or process
groups.
If no signal is specified, the
.Dv TERM
signal is sent.
If a job is specified, the signal is sent to the job's process group.
See
.Sx Job control
below for the format of
.Ar job .
.Pp
.It Xo
.Ic kill
.Fl l
.Op Ar exit-status ...
.Xc
Print the signal name corresponding to
.Ar exit-status .
If no arguments are specified, a list of all the signals with their numbers
and a short description of each are printed.
.Pp
.It Ic let Op Ar expression ...
Each expression is evaluated (see
.Sx Arithmetic expressions
above).
If all expressions are successfully evaluated, the exit status is 0 (1)
if the last expression evaluated to non-zero (zero).
If an error occurs during
the parsing or evaluation of an expression, the exit status is greater than 1.
Since expressions may need to be quoted,
.No \&(( Ar expr No ))
is syntactic sugar for:
.Dl "{ \e\ebuiltin let \*(aq" Ns Ar expr Ns "\*(aq; }"
.Pp
.It Xo
.Ic mknod
.Op Fl m Ar mode
.Ar name
.Cm b\*(Bac
.Ar major minor
.Xc
.It Xo
.Ic mknod
.Op Fl m Ar mode
.Ar name
.Cm p
.Xc
Create a device special file.
The file type may be
.Cm b
(block type device),
.Cm c
(character type device)
or
.Cm p
.Pq named pipe , Tn FIFO .
The file created may be modified according to its
.Ar mode
(via the
.Fl m
option),
.Ar major
(major device number),
and
.Ar minor
(minor device number).
This is not normally part of
.Nm mksh ;
however, distributors may have added this as builtin as a speed hack.
.Pp
.It Xo
.Ic print
.Oo Fl AcelNnprsu Ns Oo Ar n Oc \*(Ba
.Fl R Op Fl n Oc
.Op Ar argument ...
.Xc
Print the specified argument(s) on the standard output,
separated by spaces, terminated with a newline.
The escapes mentioned in
.Sx Backslash expansion
above, as well as
.Dq Li \ec ,
which is equivalent to using the
.Fl n
option, are interpreted.
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl A
Each
.Ar argument
is arithmetically evaluated; the character corresponding to the
resulting value is printed.
Empty
.Ar argument Ns s
separate input words.
.It Fl c
The output is printed columnised, line by line, similar to how the
.Xr rs 1
utility, tab completion, the
.Ic kill Fl l
built-in utility and the
.Ic select
statement do.
.It Fl e
Restore backslash expansion after a previous
.Fl r .
.It Fl l
Change the output word separator to newline.
.It Fl N
Change the output word and line separator to ASCII NUL.
.It Fl n
Do not print the trailing line separator.
.It Fl p
Print to the co-process (see
.Sx Co-processes
above).
.It Fl r
Inhibit backslash expansion.
.It Fl s
Print to the history file instead of standard output.
.It Fl u Ns Op Ar n
Print to the file descriptor
.Ar n Pq defaults to 1 if omitted
instead of standard output.
.El
.Pp
The
.Fl R
option mostly emulates the
.Bx
.Xr echo 1
command which does not expand backslashes and interprets
its first argument as option only if it is exactly
.Dq Li \-n
.Pq to suppress the trailing newline .
.Pp
.It Ic pwd Op Fl LP
Print the present working directory.
If the
.Fl L
option is used or if the
.Ic physical
option isn't set (see the
.Ic set
command below), the logical path is printed (i.e. the path used to
.Ic cd
to the current directory).
If the
.Fl P
option (physical path) is used or if the
.Ic physical
option is set, the path determined from the filesystem (by following
.Dq Li ..
directories to the root directory) is printed.
.Pp
.It Xo
.Ic read
.Op Fl A \*(Ba Fl a
.Op Fl d Ar x
.Oo Fl N Ar z \*(Ba
.Fl n Ar z Oc
.Oo Fl p \*(Ba
.Fl u Ns Op Ar n
.Oc Op Fl t Ar n
.Op Fl rs
.Op Ar p ...
.Xc
Reads a line of input, separates the input into fields using the
.Ev IFS
parameter (see
.Sx Substitution
above), and assigns each field to the specified parameters
.Ar p .
If no parameters are specified, the
.Ev REPLY
parameter is used to store the result.
With the
.Fl A
and
.Fl a
options, only no or one parameter is accepted.
If there are more parameters than fields, the extra parameters are set to
the empty string or 0; if there are more fields than parameters, the last
parameter is assigned the remaining fields (including the word separators).
.Pp
The options are as follows:
.Bl -tag -width XuXnX
.It Fl A
Store the result into the parameter
.Ar p
(or
.Ev REPLY )
as array of words.
.It Fl a
Store the result without word splitting into the parameter
.Ar p
(or
.Ev REPLY )
as array of characters (wide characters if the
.Ic utf8\-mode
option is enacted, octets otherwise); the codepoints are
encoded as decimal numbers by default.
.It Fl d Ar x
Use the first byte of
.Ar x ,
.Dv NUL
if empty, instead of the ASCII newline character as input line delimiter.
.It Fl N Ar z
Instead of reading till end-of-line, read exactly
.Ar z
bytes.
Upon EOF, a partial read is returned with exit status 1.
After timeout, a partial read is returned with an exit status as if
.Dv SIGALRM
were caught.
.It Fl n Ar z
Instead of reading till end-of-line, read up to
.Ar z
bytes but return as soon as any bytes are read, e.g.\& from a
slow terminal device, or if EOF or a timeout occurs.
.It Fl p
Read from the currently active co-process, see
.Sx Co-processes
above for details on this.
.It Fl u Ns Op Ar n
Read from the file descriptor
.Ar n
(defaults to 0, i.e.\& standard input).
The argument must immediately follow the option character.
.It Fl t Ar n
Interrupt reading after
.Ar n
seconds (specified as positive decimal value with an optional fractional part).
The exit status of
.Nm read
is the same as if
.Dv SIGALRM
were caught if the timeout occurred, but partial reads may still be returned.
.It Fl r
Normally, the ASCII backslash character escapes the special
meaning of the following character and is stripped from the input;
.Ic read
does not stop when encountering a backslash-newline sequence and
does not store that newline in the result.
This option enables raw mode, in which backslashes are not processed.
.It Fl s
The input line is saved to the history.
.El
.Pp
If the input is a terminal, both the
.Fl N
and
.Fl n
options set it into raw mode;
they read an entire file if \-1 is passed as
.Ar z
argument.
.Pp
The first parameter may have a question mark and a string appended to it, in
which case the string is used as a prompt (printed to standard error before
any input is read) if the input is a
.Xr tty 4
(e.g.\&
.Ic read nfoo?\*(aqnumber of foos: \*(aq ) .
.Pp
If no input is read or a timeout occurred,
.Ic read
exits with a non-zero status.
.Pp
.It Xo
.Ic readonly
.Op Fl p
.Oo Ar parameter
.Op Ns = Ns Ar value
.Ar ... Oc
.Xc
Sets the read-only attribute of the named parameters.
This is a declaration utility.
If values are given,
parameters are set to them before setting the attribute.
Once a parameter is
made read-only, it cannot be unset and its value cannot be changed.
.Pp
If no parameters are specified, the names of all parameters with the read-only
attribute are printed one per line, unless the
.Fl p
option is used, in which case
.Ic readonly
commands defining all read-only parameters, including their values, are
printed.
.Pp
.It Xo
.Ic realpath
.Op Fl \-
.Ar name
.Xc
Prints the resolved absolute pathname corresponding to
.Ar name .
If
.Ar name
ends with a slash
.Pq Ql / ,
it's also checked for existence and whether it is a directory; otherwise,
.Ic realpath
returns 0 if the pathname either exists or can be created immediately,
i.e. all but the last component exist and are directories.
For calls from the shell, if any options are given, an external
.Xr realpath 1
utility is preferred over the builtin.
.Pp
.It Xo
.Ic rename
.Op Fl \-
.Ar from to
.Xc
Renames the file
.Ar from
to
.Ar to .
Both must be complete pathnames and on the same device.
An external utility is preferred over this builtin,
which is intended for emergency situations
.Pq where Pa /bin/mv No becomes unusable
and directly calls
.Xr rename 2 .
.Pp
.It Ic return Op Ar status
Returns from a function or
.Ic \&.
script, with exit status
.Ar status .
If no
.Ar status
is given, the exit status of the last executed command is used.
If used outside of a function or
.Ic \&.
script, it has the same effect as
.Ic exit .
Note that
.Nm
treats both profile and
.Ev ENV
files as
.Ic \&.
scripts, while the original Korn shell only treats profiles as
.Ic \&.
scripts.
.Pp
.It Xo
.Ic set Op Ic +\-abCefhiklmnprsUuvXx
.Op Ic +\-o Ar option
.Op Ic +\-A Ar name
.Op Fl \-
.Op Ar arg ...
.Xc
The
.Ic set
command can be used to set
.Pq Ic \-
or clear
.Pq Ic +
shell options, set the positional parameters, or set an array parameter.
Options can be changed using the
.Cm +\-o Ar option
syntax, where
.Ar option
is the long name of an option, or using the
.Cm +\- Ns Ar letter
syntax, where
.Ar letter
is the option's single letter name (not all options have a single letter name).
The following table lists both option letters (if they exist) and long names
along with a description of what the option does:
.Bl -tag -width 3n
.It Fl A Ar name
Sets the elements of the array parameter
.Ar name
to
.Ar arg ...
If
.Fl A
is used, the array is reset (i.e. emptied) first; if
.Ic +A
is used, the first N elements are set (where N is the number of arguments);
the rest are left untouched.
.Pp
An alternative syntax for the command
.Ic set \-A foo \-\- a b c
which is compatible to
.Tn GNU
.Nm bash
and also supported by
.At
.Nm ksh93
is:
.Ic foo=(a b c); foo+=(d e)
.It Fl a \*(Ba Fl o Ic allexport
All new parameters are created with the export attribute.
.It Fl b \*(Ba Fl o Ic notify
Print job notification messages asynchronously, instead of just before the
prompt.
Only used if job control is enabled
.Pq Fl m .
.It Fl C \*(Ba Fl o Ic noclobber
Prevent \*(Gt redirection from overwriting existing files.
Instead, \*(Gt\*(Ba must be used to force an overwrite.
Note that this is not safe to use for creation of temporary files or
lockfiles due to a TOCTOU in a check allowing one to redirect output to
.Pa /dev/null
or other device files even in
.Ic noclobber
mode.
.It Fl e \*(Ba Fl o Ic errexit
Exit (after executing the
.Dv ERR
trap) as soon as an error occurs or a command fails (i.e. exits with a
non-zero status).
This does not apply to commands whose exit status is
explicitly tested by a shell construct such as
.Ic if ,
.Ic until ,
.Ic while
or
.Ic \&!
statements.
For
.Ic &&
or
.Ic \*(Ba\*(Ba ,
only the status of the last command is tested.
.It Fl f \*(Ba Fl o Ic noglob
Do not expand file name patterns.
.It Fl h \*(Ba Fl o Ic trackall
Create tracked aliases for all executed commands (see
.Sx Aliases
above).
Enabled by default for non-interactive shells.
.It Fl i \*(Ba Fl o Ic interactive
The shell is an interactive shell.
This option can only be used when the shell is invoked.
See above for a description of what this means.
.It Fl k \*(Ba Fl o Ic keyword
Parameter assignments are recognised anywhere in a command.
.It Fl l \*(Ba Fl o Ic login
The shell is a login shell.
This option can only be used when the shell is invoked.
See above for a description of what this means.
.It Fl m \*(Ba Fl o Ic monitor
Enable job control (default for interactive shells).
.It Fl n \*(Ba Fl o Ic noexec
Do not execute any commands.
Useful for checking the syntax of scripts
(ignored if interactive).
.It Fl p \*(Ba Fl o Ic privileged
The shell is a privileged shell.
It is set automatically if, when the shell starts,
the real UID or GID does not match
the effective UID (EUID) or GID (EGID), respectively.
See above for a description of what this means.
.It Fl r \*(Ba Fl o Ic restricted
The shell is a restricted shell.
This option can only be used when the shell is invoked.
See above for a description of what this means.
.It Fl s \*(Ba Fl o Ic stdin
If used when the shell is invoked, commands are read from standard input.
Set automatically if the shell is invoked with no arguments.
.Pp
When
.Fl s
is used with the
.Ic set
command it causes the specified arguments to be sorted before assigning them to
the positional parameters (or to array
.Ar name ,
if
.Fl A
is used).
.It Fl U \*(Ba Fl o Ic utf8\-mode
Enable UTF-8 support in the
.Sx Emacs editing mode
and internal string handling functions.
This flag is disabled by default, but can be enabled by setting it on the
shell command line; is enabled automatically for interactive shells if
requested at compile time, your system supports
.Fn setlocale LC_CTYPE \&""
and optionally
.Fn nl_langinfo CODESET ,
or the
.Ev LC_ALL ,
.Ev LC_CTYPE
or
.Ev LANG
environment variables,
and at least one of these returns something that matches
.Dq UTF\-8
or
.Dq utf8
case-insensitively; for direct builtin calls depending on the
aforementioned environment variables; or for stdin or scripts,
if the input begins with a UTF-8 Byte Order Mark.
.Pp
In near future, locale tracking will be implemented, which means that
.Ic set Fl +U
is changed whenever one of the
.Tn POSIX
locale-related environment variables changes.
.It Fl u \*(Ba Fl o Ic nounset
Referencing of an unset parameter, other than
.Dq Li $@
or
.Dq Li $* ,
is treated as an error, unless one of the
.Ql \- ,
.Ql +
or
.Ql =
modifiers is used.
.It Fl v \*(Ba Fl o Ic verbose
Write shell input to standard error as it is read.
.It Fl X \*(Ba Fl o Ic markdirs
Mark directories with a trailing
.Ql /
during file name generation.
.It Fl x \*(Ba Fl o Ic xtrace
Print command trees when they are executed, preceded by
the value of
.Ev PS4 .
.It Fl o Ic bgnice
Background jobs are run with lower priority.
.It Fl o Ic braceexpand
Enable brace expansion (a.k.a. alternation).
This is enabled by default.
.It Fl o Ic emacs
Enable BRL emacs-like command-line editing (interactive shells only); see
.Sx Emacs editing mode .
.It Fl o Ic gmacs
Enable gmacs-like command-line editing (interactive shells only).
Currently identical to emacs editing except that transpose\-chars (\*(haT) acts
slightly differently.
.It Fl o Ic ignoreeof
The shell will not (easily) exit when end-of-file is read;
.Ic exit
must be used.
To avoid infinite loops, the shell will exit if
.Dv EOF
is read 13 times in a row.
.It Fl o Ic inherit\-xtrace
Do not reset
.Fl o Ic xtrace
upon entering functions.
This is enabled by default.
.It Fl o Ic nohup
Do not kill running jobs with a
.Dv SIGHUP
signal when a login shell exits.
Currently set by default, but this may
change in the future to be compatible with
.At
.Nm ksh ,
which
doesn't have this option, but does send the
.Dv SIGHUP
signal.
.It Fl o Ic nolog
No effect.
In the original Korn shell, this prevents function definitions from
being stored in the history file.
.It Fl o Ic physical
Causes the
.Ic cd
and
.Ic pwd
commands to use
.Dq physical
(i.e. the filesystem's)
.Dq Li ..
directories instead of
.Dq logical
directories (i.e. the shell handles
.Dq Li .. ,
which allows the user to be oblivious of symbolic links to directories).
Clear by default.
Note that setting this option does not affect the current value of the
.Ev PWD
parameter; only the
.Ic cd
command changes
.Ev PWD .
See the
.Ic cd
and
.Ic pwd
commands above for more details.
.It Fl o Ic pipefail
Make the exit status of a pipeline (before logically complementing) the
rightmost non-zero errorlevel, or zero if all commands exited with zero.
.It Fl o Ic posix
Behave closer to the standards
(see
.Sx POSIX mode
for details).
Automatically enabled if the basename of the shell invocation begins with
.Dq sh
and this autodetection feature is compiled in
.Pq not in MirBSD .
As a side effect, setting this flag turns off the
.Ic braceexpand
and
.Ic utf8\-mode
flags, which can be turned back on manually, and
.Ic sh
mode (unless both are enabled at the same time).
.It Fl o Ic sh
Enable
.Pa /bin/sh
.Pq kludge
mode (see
.Sx SH mode ) .
Automatically enabled if the basename of the shell invocation begins with
.Dq sh
and this autodetection feature is compiled in
.Pq not in MirBSD .
As a side effect, setting this flag turns off
.Ic braceexpand
mode, which can be turned back on manually, and
.Ic posix
mode (unless both are enabled at the same time).
.It Fl o Ic vi
Enable
.Xr vi 1 Ns -like
command-line editing (interactive shells only).
See
.Sx Vi editing mode
for documentation and limitations.
.It Fl o Ic vi\-esccomplete
In vi command-line editing, do command and file name completion when escape
(\*(ha[) is entered in command mode.
.It Fl o Ic vi\-tabcomplete
In vi command-line editing, do command and file name completion when tab (\*(haI)
is entered in insert mode.
This is the default.
.It Fl o Ic viraw
No effect.
In the original Korn shell, unless
.Ic viraw
was set, the vi command-line mode would let the
.Xr tty 4
driver do the work until ESC (\*(ha[) was entered.
.Nm
is always in viraw mode.
.El
.Pp
These options can also be used upon invocation of the shell.
The current set of
options (with single letter names) can be found in the parameter
.Dq Li $\- .
.Ic set Fl o
with no option name will list all the options and whether each is on or off;
.Ic set +o
will print the long names of all options that are currently on.
In a future version,
.Ic set +o
will behave
.Tn POSIX
compliant and print commands to restore the current options instead.
.Pp
Remaining arguments, if any, are positional parameters and are assigned, in
order, to the positional parameters (i.e. $1, $2, etc.).
If options end with
.Dq Li \-\-
and there are no remaining arguments, all positional parameters are cleared.
If no options or arguments are given, the values of all names are printed.
For unknown historical reasons, a lone
.Dq Li \-
option is treated specially \*(en it clears both the
.Fl v
and
.Fl x
options.
.Pp
.It Ic shift Op Ar number
The positional parameters
.Ar number Ns +1 ,
.Ar number Ns +2 ,
etc. are renamed to 1, 2, etc.
.Ar number
defaults to 1.
.Pp
.It Ic sleep Ar seconds
Suspends execution for a minimum of the
.Ar seconds
specified as positive decimal value with an optional fractional part.
Signal delivery may continue execution earlier.
.Pp
.It Ic source Ar file Op Ar arg ...
Like
.Ic \&. Po Do dot Dc Pc ,
except that the current working directory is appended to the
search path (GNU
.Nm bash
extension).
.Pp
.It Ic suspend
Stops the shell as if it had received the suspend character from
the terminal.
It is not possible to suspend a login shell unless the parent process
is a member of the same terminal session but is a member of a different
process group.
As a general rule, if the shell was started by another shell or via
.Xr su 1 ,
it can be suspended.
.Pp
.It Ic test Ar expression
.It Ic \&[ Ar expression Ic \&]
.Ic test
evaluates the
.Ar expression
and returns zero status if true, 1 if false, or greater than 1 if there
was an error.
It is normally used as the condition command of
.Ic if
and
.Ic while
statements.
Symbolic links are followed for all
.Ar file
expressions except
.Fl h
and
.Fl L .
.Pp
The following basic expressions are available:
.Bl -tag -width 17n
.It Fl a Ar file
.Ar file
exists.
.It Fl b Ar file
.Ar file
is a block special device.
.It Fl c Ar file
.Ar file
is a character special device.
.It Fl d Ar file
.Ar file
is a directory.
.It Fl e Ar file
.Ar file
exists.
.It Fl f Ar file
.Ar file
is a regular file.
.It Fl G Ar file
.Ar file Ns 's
group is the shell's effective group ID.
.It Fl g Ar file
.Ar file Ns 's
mode has the setgid bit set.
.It Fl H Ar file
.Ar file
is a context dependent directory (only useful on HP-UX).
.It Fl h Ar file
.Ar file
is a symbolic link.
.It Fl k Ar file
.Ar file Ns 's
mode has the
.Xr sticky 8
bit set.
.It Fl L Ar file
.Ar file
is a symbolic link.
.It Fl O Ar file
.Ar file Ns 's
owner is the shell's effective user ID.
.It Fl p Ar file
.Ar file
is a named pipe
.Pq Tn FIFO .
.It Fl r Ar file
.Ar file
exists and is readable.
.It Fl S Ar file
.Ar file
is a
.Xr unix 4 Ns -domain
socket.
.It Fl s Ar file
.Ar file
is not empty.
.It Fl t Ar fd
File descriptor
.Ar fd
is a
.Xr tty 4
device.
.It Fl u Ar file
.Ar file Ns 's
mode has the setuid bit set.
.It Fl w Ar file
.Ar file
exists and is writable.
.It Fl x Ar file
.Ar file
exists and is executable.
.It Ar file1 Fl nt Ar file2
.Ar file1
is newer than
.Ar file2
or
.Ar file1
exists and
.Ar file2
does not.
.It Ar file1 Fl ot Ar file2
.Ar file1
is older than
.Ar file2
or
.Ar file2
exists and
.Ar file1
does not.
.It Ar file1 Fl ef Ar file2
.Ar file1
is the same file as
.Ar file2 .
.It Ar string
.Ar string
has non-zero length.
.It Fl n Ar string
.Ar string
is not empty.
.It Fl z Ar string
.Ar string
is empty.
.It Fl v Ar name
The shell parameter
.Ar name
is set.
.It Fl o Ar option
Shell
.Ar option
is set (see the
.Ic set
command above for a list of options).
As a non-standard extension, if the option starts with a
.Ql \&! ,
the test is negated; the test always fails if
.Ar option
doesn't exist (so [ \-o foo \-o \-o !foo ] returns true if and only if option
.Ar foo
exists).
The same can be achieved with [ \-o ?foo ] like in
.At
.Nm ksh93 .
.Ar option
can also be the short flag led by either
.Ql \-
or
.Ql +
.Pq no logical negation ,
for example
.Dq Li \-x
or
.Dq Li +x
instead of
.Dq Li xtrace .
.It Ar string No = Ar string
Strings are equal.
.It Ar string No == Ar string
Strings are equal.
.It Ar string No \*(Gt Ar string
First string operand is greater than second string operand.
.It Ar string No \*(Lt Ar string
First string operand is less than second string operand.
.It Ar string No != Ar string
Strings are not equal.
.It Ar number Fl eq Ar number
Numbers compare equal.
.It Ar number Fl ne Ar number
Numbers compare not equal.
.It Ar number Fl ge Ar number
Numbers compare greater than or equal.
.It Ar number Fl gt Ar number
Numbers compare greater than.
.It Ar number Fl le Ar number
Numbers compare less than or equal.
.It Ar number Fl \&lt Ar number
Numbers compare less than.
.El
.Pp
The above basic expressions, in which unary operators have precedence over
binary operators, may be combined with the following operators (listed in
increasing order of precedence):
.Bd -literal -offset indent
expr \-o expr		Logical OR.
expr \-a expr		Logical AND.
! expr			Logical NOT.
( expr )		Grouping.
.Ed
.Pp
Note that a number actually may be an arithmetic expression, such as
a mathematical term or the name of an integer variable:
.Bd -literal -offset indent
x=1; [ "x" \-eq 1 ]	evaluates to true
.Ed
.Pp
Note that some special rules are applied (courtesy of
.Px
) if the number of arguments to
.Ic test
or inside the brackets
.Ic \&[ ... \&]
is less than five: if leading
.Dq Li \&!
arguments can be stripped such that only one to three arguments remain,
then the lowered comparison is executed; (thanks to XSI) parentheses
.Ic \e( ... \e)
lower four- and three-argument forms to two- and one-argument forms,
respectively; three-argument forms ultimately prefer binary operations,
followed by negation and parenthesis lowering; two- and four-argument forms
prefer negation followed by parenthesis; the one-argument form always implies
.Fl n .
.Pp
.Sy Note :
A common mistake is to use
.Dq Li if \&[ $foo = bar \&]
which fails if parameter
.Dq foo
is empty or unset, if it has embedded spaces (i.e.\&
.Ev IFS
octets) or if it is a unary operator like
.Dq Li \&!
or
.Dq Li \-n .
Use tests like
.Dq Li if \&[ x\&"$foo\&" = x"bar" \&]
instead, or the double-bracket operator
.Dq Li if \&[[ $foo = bar \&]]
or, to avoid pattern matching (see
.Ic \&[[
above):
.Dq Li if \&[[ $foo = \&"$bar" \&]]
.Pp
The
.Ic \&[[ ... \&]]
construct is not only more secure to use but also often faster.
.Pp
.It Xo
.Ic time
.Op Fl p
.Op Ar pipeline
.Xc
If a
.Ar pipeline
is given, the times used to execute the pipeline are reported.
If no pipeline
is given, then the user and system time used by the shell itself, and all the
commands it has run since it was started, are reported.
The times reported are the real time (elapsed time from start to finish),
the user CPU time (time spent running in user mode), and the system CPU time
(time spent running in kernel mode).
Times are reported to standard error; the format of the output is:
.Pp
.Dl "0m0.03s real     0m0.02s user     0m0.01s system"
.Pp
If the
.Fl p
option is given the output is slightly longer:
.Bd -literal -offset indent
real     0.03
user     0.02
sys      0.01
.Ed
.Pp
It is an error to specify the
.Fl p
option unless
.Ar pipeline
is a simple command.
.Pp
Simple redirections of standard error do not affect the output of the
.Ic time
command:
.Pp
.Dl $ time sleep 1 2\*(Gtafile
.Dl $ { time sleep 1; } 2\*(Gtafile
.Pp
Times for the first command do not go to
.Dq afile ,
but those of the second command do.
.Pp
.It Ic times
Print the accumulated user and system times used both by the shell
and by processes that the shell started which have exited.
The format of the output is:
.Bd -literal -offset indent
0m0.01s 0m0.00s
0m0.04s 0m0.02s
.Ed
.Pp
.It Ic trap Ar n Op Ar signal ...
If the first operand is a decimal unsigned integer, this resets all
specified signals to the default action, i.e. is the same as calling
.Ic trap
with a dash
.Pq Dq Li \-
as
.Ar handler ,
followed by the arguments
.Pq Ar n Op Ar signal ... ,
all of which are treated as signals.
.Pp
.It Ic trap Op Ar handler signal ...
Sets a trap handler that is to be executed when any of the specified
.Ar signal Ns s
are received.
.Ar handler
is either an empty string, indicating the signals are to be ignored, a dash
.Pq Dq Li \- ,
indicating that the default action is to be taken for the signals
.Pq see Xr signal 3 ,
or a string containing shell commands to be executed at the first opportunity
(i.e. when the current command completes or before printing the next
.Ev PS1
prompt) after receipt of one of the signals.
.Ar signal
is the name of a signal
.Pq e.g.\& Dv PIPE or Dv ALRM
or the number of the signal (see the
.Ic kill Fl l
command above).
.Pp
There are two special signals:
.Dv EXIT
.Pq also known as 0 ,
which is executed when the shell is about to exit, and
.Dv ERR ,
which is executed after an error occurs; an error is something
that would cause the shell to exit if the
.Ic set Fl e
or
.Ic set Fl o Ic errexit
option were set.
.Dv EXIT
handlers are executed in the environment of the last executed command.
.Pp
Note that, for non-interactive shells, the trap handler cannot be changed
for signals that were ignored when the shell started.
.Pp
With no arguments, the current state of the traps that have been set since
the shell started is shown as a series of
.Ic trap
commands.
Note that the output of
.Ic trap
cannot be usefully piped to another process (an artifact of the fact that
traps are cleared when subprocesses are created).
.Pp
The original Korn shell's
.Dv DEBUG
trap and the handling of
.Dv ERR
and
.Dv EXIT
traps in functions are not yet implemented.
.Pp
.It Ic true
A command that exits with a zero value.
.Pp
.It Xo
.Ic typeset
.Op Ic +\-aglpnrtUux
.Oo Fl L Ns Op Ar n
.No \*(Ba Fl R Ns Op Ar n
.No \*(Ba Fl Z Ns Op Ar n Oc
.Op Fl i Ns Op Ar n
.Oo Ar name
.Op Ns = Ns Ar value
.Ar ... Oc
.Xc
.It Xo
.Ic typeset
.Fl f Op Fl tux
.Op Ar name ...
.Xc
Display or set parameter attributes.
This is a declaration utility.
With no
.Ar name
arguments, parameter attributes are displayed; if no options are used, the
current attributes of all parameters are printed as
.Ic typeset
commands; if an option is given (or
.Dq Li \-
with no option letter), all parameters and their values with the specified
attributes are printed; if options are introduced with
.Ql + ,
parameter values are not printed.
.Pp
If
.Ar name
arguments are given, the attributes of the named parameters are set
.Pq Ic \&\-
or cleared
.Pq Ic \&+ ;
inside a function, this will cause the parameters to be created
(with no value) in the local scope (but see
.Fl g ) .
Values for parameters may optionally be specified.
For
.Ar name Ns \&[*] ,
the change affects all elements of the array, and no value may be specified.
.Pp
When
.Fl f
is used,
.Ic typeset
operates on the attributes of functions.
As with parameters, if no
.Ar name
arguments are given,
functions are listed with their values (i.e. definitions) unless
options are introduced with
.Ql + ,
in which case only the function names are reported.
.Bl -tag -width Ds
.It Fl a
Indexed array attribute.
.It Fl f
Function mode.
Display or set functions and their attributes, instead of parameters.
.It Fl g
Do not cause named parameters to be created in
the local scope when called inside a function.
.It Fl i Ns Op Ar n
Integer attribute.
.Ar n
specifies the base to use when displaying the integer (if not specified, the
base given in the first assignment is used).
Parameters with this attribute may
be assigned values containing arithmetic expressions.
.It Fl L Ns Op Ar n
Left justify attribute.
.Ar n
specifies the field width.
If
.Ar n
is not specified, the current width of a parameter (or the width of its first
assigned value) is used.
Leading whitespace (and zeros, if used with the
.Fl Z
option) is stripped.
If necessary, values are either truncated or space padded
to fit the field width.
.It Fl l
Lower case attribute.
All upper case ASCII characters in values are converted to lower case.
(In the original Korn shell, this parameter meant
.Dq long integer
when used with the
.Fl i
option.)
.It Fl n
Create a bound variable (name reference): any access to the variable
.Ar name
will access the variable
.Ar value
in the current scope (this is different from
.At
.Nm ksh93 ! )
instead.
Also different from
.At
.Nm ksh93
is that
.Ar value
is lazily evaluated at the time
.Ar name
is accessed.
This can be used by functions to access variables whose names are
passed as parameters, instead of using
.Ic eval .
.It Fl p
Print complete
.Ic typeset
commands that can be used to re-create the attributes and values of
parameters.
.It Fl R Ns Op Ar n
Right justify attribute.
.Ar n
specifies the field width.
If
.Ar n
is not specified, the current width of a parameter (or the width of its first
assigned value) is used.
Trailing whitespace is stripped.
If necessary, values are either stripped of leading characters or space
padded to make them fit the field width.
.It Fl r
Read-only attribute.
Parameters with this attribute may not be assigned to or unset.
Once this attribute is set, it cannot be turned off.
.It Fl t
Tag attribute.
Has no meaning to the shell; provided for application use.
.Pp
For functions,
.Fl t
is the trace attribute.
When functions with the trace attribute are executed, the
.Ic xtrace
.Pq Fl x
shell option is temporarily turned on.
.It Fl U
Unsigned integer attribute.
Integers are printed as unsigned values (combine with the
.Fl i
option).
This option is not in the original Korn shell.
.It Fl u
Upper case attribute.
All lower case ASCII characters in values are converted to upper case.
(In the original Korn shell, this parameter meant
.Dq unsigned integer
when used with the
.Fl i
option which meant upper case letters would never be used for bases greater
than 10.
See
.Fl U
above.)
.Pp
For functions,
.Fl u
is the undefined attribute.
See
.Sx Functions
above for the implications of this.
.It Fl x
Export attribute.
Parameters are placed in the environment of any executed commands.
Functions cannot be exported for security reasons
.Pq Dq shellshock .
.It Fl Z Ns Op Ar n
Zero fill attribute.
If not combined with
.Fl L ,
this is the same as
.Fl R ,
except zero padding is used instead of space padding.
For integers, the number is padded, not the base.
.El
.Pp
If any of the
.\" long integer ,
.Fl i ,
.Fl L ,
.Fl l ,
.Fl R ,
.Fl U ,
.Fl u
or
.Fl Z
options are changed, all others from this set are cleared,
unless they are also given on the same command line.
.Pp
.It Xo
.Ic ulimit
.Op Fl aBCcdefHilMmnOPpqrSsTtVvw
.Op Ar value
.Xc
Display or set process limits.
If no options are used, the file size limit
.Pq Fl f
is assumed.
.Ar value ,
if specified, may be either an arithmetic expression or the word
.Dq unlimited .
The limits affect the shell and any processes created by the shell after a
limit is imposed.
Note that some systems may not allow limits to be increased
once they are set.
Also note that the types of limits available are system
dependent \*(en some systems have only the
.Fl f
limit, or not even that, or can set only the soft limits
.Bl -tag -width 5n
.It Fl a
Display all limits; unless
.Fl H
is used, soft limits are displayed.
.It Fl B Ar n
Set the socket buffer size to
.Ar n
kibibytes.
.It Fl C Ar n
Set the number of cached threads to
.Ar n .
.It Fl c Ar n
Impose a size limit of
.Ar n
blocks on the size of core dumps.
.It Fl d Ar n
Impose a size limit of
.Ar n
kibibytes on the size of the data area.
.It Fl e Ar n
Set the maximum niceness to
.Ar n .
.It Fl f Ar n
Impose a size limit of
.Ar n
blocks on files written by the shell and its child processes (files of any
size may be read).
.It Fl H
Set the hard limit only (the default is to set both hard and soft limits).
.It Fl i Ar n
Set the number of pending signals to
.Ar n .
.It Fl l Ar n
Impose a limit of
.Ar n
kibibytes on the amount of locked (wired) physical memory.
.It Fl M Ar n
Set the AIO locked memory to
.Ar n
kibibytes.
.It Fl m Ar n
Impose a limit of
.Ar n
kibibytes on the amount of physical memory used.
.It Fl n Ar n
Impose a limit of
.Ar n
file descriptors that can be open at once.
.It Fl O Ar n
Set the number of AIO operations to
.Ar n .
.It Fl P Ar n
Limit the number of threads per process to
.Ar n .
.It Fl p Ar n
Impose a limit of
.Ar n
processes that can be run by the user at any one time.
.It Fl q Ar n
Limit the size of
.Tn POSIX
message queues to
.Ar n
bytes.
.It Fl r Ar n
Set the maximum real-time priority to
.Ar n .
.It Fl S
Set the soft limit only (the default is to set both hard and soft limits).
.It Fl s Ar n
Impose a size limit of
.Ar n
kibibytes on the size of the stack area.
.It Fl T Ar n
Impose a time limit of
.Ar n
real seconds to be used by each process.
.It Fl t Ar n
Impose a time limit of
.Ar n
CPU seconds spent in user mode to be used by each process.
.It Fl V Ar n
Set the number of vnode monitors on Haiku to
.Ar n .
.It Fl v Ar n
Impose a limit of
.Ar n
kibibytes on the amount of virtual memory (address space) used.
.It Fl w Ar n
Impose a limit of
.Ar n
kibibytes on the amount of swap space used.
.El
.Pp
As far as
.Ic ulimit
is concerned, a block is 512 bytes.
.Pp
.It Xo
.Ic umask
.Op Fl S
.Op Ar mask
.Xc
Display or set the file permission creation mask or umask (see
.Xr umask 2 ) .
If the
.Fl S
option is used, the mask displayed or set is symbolic; otherwise, it is an
octal number.
.Pp
Symbolic masks are like those used by
.Xr chmod 1 .
When used, they describe what permissions may be made available (as opposed to
octal masks in which a set bit means the corresponding bit is to be cleared).
For example,
.Dq Li ug=rwx,o=
sets the mask so files will not be readable, writable or executable by
.Dq others ,
and is equivalent (on most systems) to the octal mask
.Dq Li 007 .
.Pp
.It Xo
.Ic unalias
.Op Fl adt
.Op Ar name ...
.Xc
The aliases for the given names are removed.
If the
.Fl a
option is used, all aliases are removed.
If the
.Fl t
or
.Fl d
options are used, the indicated operations are carried out on tracked or
directory aliases, respectively.
.Pp
.It Xo
.Ic unset
.Op Fl fv
.Ar parameter ...
.Xc
Unset the named parameters
.Po
.Fl v ,
the default
.Pc
or functions
.Pq Fl f .
With
.Ar parameter Ns \&[*] ,
attributes are kept, only values are unset.
.Pp
The exit status is non-zero if any of the parameters have the read-only
attribute set, zero otherwise.
.Pp
.It Ic wait Op Ar job ...
Wait for the specified job(s) to finish.
The exit status of
.Ic wait
is that of the last specified job; if the last job is killed by a signal, the
exit status is 128 + the number of the signal (see
.Ic kill Fl l Ar exit-status
above); if the last specified job can't be found (because it never existed or
had already finished), the exit status of
.Ic wait
is 127.
See
.Sx Job control
below for the format of
.Ar job .
.Ic wait
will return if a signal for which a trap has been set is received or if a
.Dv SIGHUP ,
.Dv SIGINT
or
.Dv SIGQUIT
signal is received.
.Pp
If no jobs are specified,
.Ic wait
waits for all currently running jobs (if any) to finish and exits with a zero
status.
If job monitoring is enabled, the completion status of jobs is printed
(this is not the case when jobs are explicitly specified).
.Pp
.It Xo
.Ic whence
.Op Fl pv
.Op Ar name ...
.Xc
Without the
.Fl v
option, it is the same as
.Ic command Fl v ,
except aliases are not printed as alias command.
With the
.Fl v
option, it is exactly the same as
.Ic command Fl V .
In either case, the
.Fl p
option differs: the search path is not affected in
.Ic whence ,
but the search is restricted to the path.
.El
.Ss Job control
Job control refers to the shell's ability to monitor and control jobs which
are processes or groups of processes created for commands or pipelines.
At a minimum, the shell keeps track of the status of the background (i.e.\&
asynchronous) jobs that currently exist; this information can be displayed
using the
.Ic jobs
commands.
If job control is fully enabled (using
.Ic set Fl m
or
.Ic set Fl o Ic monitor ) ,
as it is for interactive shells, the processes of a job are placed in their
own process group.
Foreground jobs can be stopped by typing the suspend character from
the terminal (normally \*(haZ); jobs can be restarted in either the
foreground or background using the commands
.Ic fg
and
.Ic bg .
.Pp
Note that only commands that create processes (e.g. asynchronous commands,
subshell commands and non-built-in, non-function commands) can be stopped;
commands like
.Ic read
cannot be.
.Pp
When a job is created, it is assigned a job number.
For interactive shells, this number is printed inside
.Dq Li \&[...] ,
followed by the process IDs of the processes in the job when an asynchronous
command is run.
A job may be referred to in the
.Ic bg ,
.Ic fg ,
.Ic jobs ,
.Ic kill
and
.Ic wait
commands either by the process ID of the last process in the command pipeline
(as stored in the
.Ic \&$!
parameter) or by prefixing the job number with a percent sign
.Pq Ql % .
Other percent sequences can also be used to refer to jobs:
.Bl -tag -width "%+ x %% x %XX"
.It %+ \*(Ba %% \*(Ba %
The most recently stopped job or, if there are no stopped jobs, the oldest
running job.
.It %\-
The job that would be the
.Ic %+
job if the latter did not exist.
.It % Ns Ar n
The job with job number
.Ar n .
.It %? Ns Ar string
The job with its command containing the string
.Ar string
(an error occurs if multiple jobs are matched).
.It % Ns Ar string
The job with its command starting with the string
.Ar string
(an error occurs if multiple jobs are matched).
.El
.Pp
When a job changes state (e.g. a background job finishes or foreground job is
stopped), the shell prints the following status information:
.Pp
.D1 [ Ns Ar number ] Ar flag status command
.Pp
where...
.Bl -tag -width "command"
.It Ar number
is the job number of the job;
.It Ar flag
is the
.Ql +
or
.Ql \-
character if the job is the
.Ic %+
or
.Ic %\-
job, respectively, or space if it is neither;
.It Ar status
indicates the current state of the job and can be:
.Bl -tag -width "RunningXX"
.It Done Op Ar number
The job exited.
.Ar number
is the exit status of the job which is omitted if the status is zero.
.It Running
The job has neither stopped nor exited (note that running does not necessarily
mean consuming CPU time \*(en
the process could be blocked waiting for some event).
.It Stopped Op Ar signal
The job was stopped by the indicated
.Ar signal
(if no signal is given, the job was stopped by
.Dv SIGTSTP ) .
.It Ar signal-description Op Dq core dumped
The job was killed by a signal (e.g. memory fault, hangup); use
.Ic kill Fl l
for a list of signal descriptions.
The
.Dq Li core dumped
message indicates the process created a core file.
.El
.It Ar command
is the command that created the process.
If there are multiple processes in
the job, each process will have a line showing its
.Ar command
and possibly its
.Ar status ,
if it is different from the status of the previous process.
.El
.Pp
When an attempt is made to exit the shell while there are jobs in the stopped
state, the shell warns the user that there are stopped jobs and does not exit.
If another attempt is immediately made to exit the shell, the stopped jobs are
sent a
.Dv SIGHUP
signal and the shell exits.
Similarly, if the
.Ic nohup
option is not set and there are running jobs when an attempt is made to exit
a login shell, the shell warns the user and does not exit.
If another attempt
is immediately made to exit the shell, the running jobs are sent a
.Dv SIGHUP
signal and the shell exits.
.Ss Terminal state
The state of the controlling terminal can be modified by a command
executed in the foreground, whether or not job control is enabled, but
the modified terminal state is only kept past the job's lifetime and used
for later command invocations if the command exits successfully (i.e.\&
with an exit status of 0).
When such a job is momentarily stopped or restarted, the terminal state
is saved and restored, respectively, but it will not be kept afterwards.
In interactive mode, when line editing is enabled, the terminal state is
saved before being reconfigured by the shell for the line editor, then
restored before running a command.
.Ss POSIX mode
Entering
.Ic set Fl o Ic posix
mode will cause
.Nm
to behave even more
.Tn POSIX
compliant in places where the defaults or opinions differ.
Note that
.Nm mksh
will still operate with unsigned 32-bit arithmetic; use
.Nm lksh
if arithmetic on the host
.Vt long
data type, complete with ISO C Undefined Behaviour, is required;
refer to the
.Xr lksh 1
manual page for details.
Most other historic,
.At
.Nm ksh Ns -compatible
or opinionated differences can be disabled by using this mode; these are:
.Bl -bullet
.It
The incompatible GNU
.Nm bash
I/O redirection
.Ic &\*(Gt Ns Ar file
is not supported.
.It
File descriptors created by I/O redirections are inherited by
child processes.
.It
Numbers with a leading digit zero are interpreted as octal.
.It
The
.Nm echo
builtin does not interpret backslashes and only supports the exact option
.Fl n .
.It
Alias expansion with a trailing space only reruns on command words.
.It
Tilde expansion follows POSIX instead of Korn shell rules.
.It
The exit status of
.Ic fg
is always 0.
.It
.Ic kill
.Fl l
only lists signal names, all in one line.
.It
.Ic getopts
does not accept options with a leading
.Ql + .
.It
.Ic exec
skips builtins, functions and other commands and uses a
.Ev PATH
search to determine the utility to execute.
.El
.Ss SH mode
Compatibility mode; intended for use with legacy scripts that
cannot easily be fixed; the changes are as follows:
.Bl -bullet
.It
The incompatible GNU
.Nm bash
I/O redirection
.Ic &\*(Gt Ns Ar file
is not supported.
.It
File descriptors created by I/O redirections are inherited by
child processes.
.It
The
.Nm echo
builtin does not interpret backslashes and only supports the exact option
.Fl n ,
unless built with
.Ev \-DMKSH_MIDNIGHTBSD01ASH_COMPAT .
.It
The substitution operations
.Sm off
.Xo
.Pf ${ Ar x
.Pf # Ar pat No } ,
.Sm on
.Xc
.Sm off
.Xo
.Pf ${ Ar x
.Pf ## Ar pat No } ,
.Sm on
.Xc
.Sm off
.Xo
.Pf ${ Ar x
.Pf % Ar pat No } ,
.Sm on
.Xc
and
.Sm off
.Xo
.Pf ${ Ar x
.Pf %% Ar pat No }
.Sm on
.Xc
wrongly do not require a parenthesis to be escaped and do not parse extglobs.
.It
The getopt construct from
.Xr lksh 1
passes through the errorlevel.
.It
.Nm sh
.Fl c
eats a leading
.Fl \-
if built with
.Ev \-DMKSH_MIDNIGHTBSD01ASH_COMPAT .
.El
.Ss Interactive input line editing
The shell supports three modes of reading command lines from a
.Xr tty 4
in an interactive session, controlled by the
.Ic emacs ,
.Ic gmacs
and
.Ic vi
options (at most one of these can be set at once).
The default is
.Ic emacs .
Editing modes can be set explicitly using the
.Ic set
built-in.
If none of these options are enabled,
the shell simply reads lines using the normal
.Xr tty 4
driver.
If the
.Ic emacs
or
.Ic gmacs
option is set, the shell allows emacs-like editing of the command; similarly,
if the
.Ic vi
option is set, the shell allows vi-like editing of the command.
These modes are described in detail in the following sections.
.Pp
In these editing modes, if a line is longer than the screen width (see the
.Ev COLUMNS
parameter),
a
.Ql \*(Gt ,
.Ql +
or
.Ql \*(Lt
character is displayed in the last column indicating that there are more
characters after, before and after, or before the current position,
respectively.
The line is scrolled horizontally as necessary.
.Pp
Completed lines are pushed into the history, unless they begin with an
IFS octet or IFS white space or are the same as the previous line.
.Ss Emacs editing mode
When the
.Ic emacs
option is set, interactive input line editing is enabled.
Warning: This mode is
slightly different from the emacs mode in the original Korn shell.
In this mode, various editing commands
(typically bound to one or more control characters) cause immediate actions
without waiting for a newline.
Several editing commands are bound to particular
control characters when the shell is invoked; these bindings can be changed
using the
.Ic bind
command.
.Pp
The following is a list of available editing commands.
Each description starts with the name of the command,
suffixed with a colon;
an
.Op Ar n
(if the command can be prefixed with a count); and any keys the command is
bound to by default, written using caret notation
e.g. the ASCII ESC character is written as \*(ha[.
These control sequences are not case sensitive.
A count prefix for a command is entered using the sequence
.Pf \*(ha[ Ns Ar n ,
where
.Ar n
is a sequence of 1 or more digits.
Unless otherwise specified, if a count is
omitted, it defaults to 1.
.Pp
Note that editing command names are used only with the
.Ic bind
command.
Furthermore, many editing commands are useful only on terminals with
a visible cursor.
The user's
.Xr tty 4
characters (e.g.\&
.Dv ERASE )
are bound to
reasonable substitutes and override the default bindings;
their customary values are shown in parentheses below.
The default bindings were chosen to resemble corresponding
Emacs key bindings:
.Bl -tag -width Ds
.It Xo abort:
.No INTR Pq \*(haC ,
.No \*(haG
.Xc
Abort the current command, save it to the history, empty the line buffer and
set the exit state to interrupted.
.It auto\-insert: Op Ar n
Simply causes the character to appear as literal input.
Most ordinary characters are bound to this.
.It Xo backward\-char:
.Op Ar n
.No \*(haB , \*(haXD , ANSI-CurLeft , PC-CurLeft
.Xc
Moves the cursor backward
.Ar n
characters.
.It Xo backward\-word:
.Op Ar n
.No \*(ha[b , ANSI-Ctrl-CurLeft , ANSI-Alt-CurLeft
.Xc
Moves the cursor backward to the beginning of the word; words consist of
alphanumerics, underscore
.Pq Ql _
and dollar sign
.Pq Ql $
characters.
.It beginning\-of\-history: \*(ha[\*(Lt
Moves to the beginning of the history.
.It beginning\-of\-line: \*(haA, ANSI-Home, PC-Home
Moves the cursor to the beginning of the edited input line.
.It Xo capitalise\-word:
.Op Ar n
.No \*(ha[C , \*(ha[c
.Xc
Uppercase the first ASCII character in the next
.Ar n
words, leaving the cursor past the end of the last word.
.It clear\-screen: \*(ha[\*(haL
Prints a compile-time configurable sequence to clear the screen and home
the cursor, redraws the last line of the prompt string and the currently
edited input line.
The default sequence works for almost all standard terminals.
.It comment: \*(ha[#
If the current line does not begin with a comment character, one is added at
the beginning of the line and the line is entered (as if return had been
pressed); otherwise, the existing comment characters are removed and the cursor
is placed at the beginning of the line.
.It complete: \*(ha[\*(ha[
Automatically completes as much as is unique of the command name or the file
name containing the cursor.
If the entire remaining command or file name is
unique, a space is printed after its completion, unless it is a directory name
in which case
.Ql /
is appended.
If there is no command or file name with the current partial word
as its prefix, a bell character is output (usually causing a beep to be
sounded).
.It complete\-command: \*(haX\*(ha[
Automatically completes as much as is unique of the command name having the
partial word up to the cursor as its prefix, as in the
.Ic complete
command above.
.It complete\-file: \*(ha[\*(haX
Automatically completes as much as is unique of the file name having the
partial word up to the cursor as its prefix, as in the
.Ic complete
command described above.
.It complete\-list: \*(haI, \*(ha[=
Complete as much as is possible of the current word
and list the possible completions for it.
If only one completion is possible,
match as in the
.Ic complete
command above.
Note that \*(haI is usually generated by the TAB (tabulator) key.
.It Xo delete\-char\-backward:
.Op Ar n
.No ERASE Pq \*(haH ,
.No \*(ha? , \*(haH
.Xc
Deletes
.Ar n
characters before the cursor.
.It Xo delete\-char\-forward:
.Op Ar n
.No ANSI-Del , PC-Del
.Xc
Deletes
.Ar n
characters after the cursor.
.It Xo delete\-word\-backward:
.Op Ar n
.No Pfx1+ERASE Pq \*(ha[\*(haH ,
.No WERASE Pq \*(haW ,
.No \*(ha[\*(ha? , \*(ha[\*(haH , \*(ha[h
.Xc
Deletes
.Ar n
words before the cursor.
.It Xo delete\-word\-forward:
.Op Ar n
.No \*(ha[d
.Xc
Deletes characters after the cursor up to the end of
.Ar n
words.
.It Xo down\-history:
.Op Ar n
.No \*(haN , \*(haXB , ANSI-CurDown , PC-CurDown
.Xc
Scrolls the history buffer forward
.Ar n
lines (later).
Each input line originally starts just after the last entry
in the history buffer, so
.Ic down\-history
is not useful until either
.Ic search\-history ,
.Ic search\-history\-up
or
.Ic up\-history
has been performed.
.It Xo downcase\-word:
.Op Ar n
.No \*(ha[L , \*(ha[l
.Xc
Lowercases the next
.Ar n
words.
.It Xo edit\-line:
.Op Ar n
.No \*(haXe
.Xc
Edit line
.Ar n
or the current line, if not specified, interactively.
The actual command executed is
.Ic fc \-e ${VISUAL:\-${EDITOR:\-vi}} Ar n .
.It end\-of\-history: \*(ha[\*(Gt
Moves to the end of the history.
.It end\-of\-line: \*(haE, ANSI-End, PC-End
Moves the cursor to the end of the input line.
.It eot: \*(ha_
Acts as an end-of-file; this is useful because edit-mode input disables
normal terminal input canonicalisation.
.It Xo eot\-or\-delete:
.Op Ar n
.No EOF Pq \*(haD
.Xc
If alone on a line, same as
.Ic eot ,
otherwise,
.Ic delete\-char\-forward .
.It error: (not bound)
Error (ring the bell).
.It evaluate\-region: \*(ha[\*(haE
Evaluates the text between the mark and the cursor position
.Pq the entire line if no mark is set
as function substitution (if it cannot be parsed, the editing state is
unchanged and the bell is rung to signal an error); $? is updated accordingly.
.It exchange\-point\-and\-mark: \*(haX\*(haX
Places the cursor where the mark is and sets the mark to where the cursor was.
.It expand\-file: \*(ha[*
Appends a
.Ql *
to the current word and replaces the word with the result of performing file
globbing on the word.
If no files match the pattern, the bell is rung.
.It Xo forward\-char:
.Op Ar n
.No \*(haF , \*(haXC , ANSI-CurRight , PC-CurRight
.Xc
Moves the cursor forward
.Ar n
characters.
.It Xo forward\-word:
.Op Ar n
.No \*(ha[f , ANSI-Ctrl-CurRight , ANSI-Alt-CurRight
.Xc
Moves the cursor forward to the end of the
.Ar n Ns th
word.
.It Xo goto\-history:
.Op Ar n
.No \*(ha[g
.Xc
Goes to history number
.Ar n .
.It Xo kill\-line:
.No KILL Pq \*(haU
.Xc
Deletes the entire input line.
.It kill\-region: \*(haW
Deletes the input between the cursor and the mark.
.It Xo kill\-to\-eol:
.Op Ar n
.No \*(haK
.Xc
Deletes the input from the cursor to the end of the line if
.Ar n
is not specified; otherwise deletes characters between the cursor and column
.Ar n .
.It list: \*(ha[?
Prints a sorted, columnated list of command names or file names (if any) that
can complete the partial word containing the cursor.
Directory names have
.Ql /
appended to them.
.It list\-command: \*(haX?
Prints a sorted, columnated list of command names (if any) that can complete
the partial word containing the cursor.
.It list\-file: \*(haX\*(haY
Prints a sorted, columnated list of file names (if any) that can complete the
partial word containing the cursor.
File type indicators are appended as described under
.Ic list
above.
.It newline: \*(haJ , \*(haM
Causes the current input line to be processed by the shell.
The current cursor position may be anywhere on the line.
.It newline\-and\-next: \*(haO
Causes the current input line to be processed by the shell, and the next line
from history becomes the current line.
This is only useful after an
.Ic up\-history ,
.Ic search\-history
or
.Ic search\-history\-up .
.It Xo no\-op:
.No QUIT Pq \*(ha\e
.Xc
This does nothing.
.It prefix\-1: \*(ha[
Introduces a 2-character command sequence.
.It prefix\-2: \*(haX , \*(ha[[ , \*(ha[O
Introduces a multi-character command sequence.
.It Xo prev\-hist\-word:
.Op Ar n
.No \*(ha[. , \*(ha[_
.Xc
The last word or, if given, the
.Ar n Ns th
word (zero-based) of the previous (on repeated execution, second-last,
third-last, etc.) command is inserted at the cursor.
Use of this editing command trashes the mark.
.It quote: \*(ha\*(ha , \*(haV
The following character is taken literally rather than as an editing command.
.It redraw: \*(haL
Reprints the last line of the prompt string and the current input line
on a new line.
.It Xo search\-character\-backward:
.Op Ar n
.No \*(ha[\*(ha]
.Xc
Search backward in the current line for the
.Ar n Ns th
occurrence of the next character typed.
.It Xo search\-character\-forward:
.Op Ar n
.No \*(ha]
.Xc
Search forward in the current line for the
.Ar n Ns th
occurrence of the next character typed.
.It search\-history: \*(haR
Enter incremental search mode.
The internal history list is searched
backwards for commands matching the input.
An initial
.Ql \*(ha
in the search string anchors the search.
The escape key will leave search mode.
Other commands, including sequences of escape as
.Ic prefix\-1
followed by a
.Ic prefix\-1
or
.Ic prefix\-2
key will be executed after leaving search mode.
The
.Ic abort Pq \*(haG
command will restore the input line before search started.
Successive
.Ic search\-history
commands continue searching backward to the next previous occurrence of the
pattern.
The history buffer retains only a finite number of lines; the oldest
are discarded as necessary.
.It search\-history\-up: ANSI-PgUp, PC-PgUp
Search backwards through the history buffer for commands whose beginning match
the portion of the input line before the cursor.
When used on an empty line, this has the same effect as
.Ic up\-history .
.It search\-history\-down: ANSI-PgDn, PC-PgDn
Search forwards through the history buffer for commands whose beginning match
the portion of the input line before the cursor.
When used on an empty line, this has the same effect as
.Ic down\-history .
This is only useful after an
.Ic up\-history ,
.Ic search\-history
or
.Ic search\-history\-up .
.It set\-mark\-command: \*(ha[ Ns Aq space
Set the mark at the cursor position.
.It transpose\-chars: \*(haT
If at the end of line or, if the
.Ic gmacs
option is set, this exchanges the two previous characters; otherwise, it
exchanges the previous and current characters and moves the cursor one
character to the right.
.It Xo up\-history:
.Op Ar n
.No \*(haP , \*(haXA , ANSI-CurUp , PC-CurUp
.Xc
Scrolls the history buffer backward
.Ar n
lines (earlier).
.It Xo upcase\-word:
.Op Ar n
.No \*(ha[U , \*(ha[u
.Xc
Uppercase the next
.Ar n
words.
.It version: \*(ha[\*(haV
Display the version of
.Nm mksh .
The current edit buffer is restored as soon as a key is pressed.
The restoring keypress is processed, unless it is a space.
.It yank: \*(haY
Inserts the most recently killed text string at the current cursor position.
.It yank\-pop: \*(ha[y
Immediately after a
.Ic yank ,
replaces the inserted text string with the next previously killed text string.
.El
.Pp
The tab completion escapes characters the same way as the following code:
.Bd -literal
print \-nr \-\- "${x@/[\e"\-\e$\e&\-*:\-?[\e\e\e\`{\-\e}${IFS\-$\*(aq \et\en\*(aq}]/\e\e$KSH_MATCH}"
.Ed
.Ss Vi editing mode
.Em Note:
The vi command-line editing mode is orphaned, yet still functional.
It is 8-bit clean but specifically does not support UTF-8 or MBCS.
.Pp
The vi command-line editor in
.Nm
has basically the same commands as the
.Xr vi 1
editor with the following exceptions:
.Bl -bullet
.It
You start out in insert mode.
.It
There are file name and command completion commands:
=, \e, *, \*(haX, \*(haE, \*(haF and, optionally,
.Aq tab
and
.Aq esc .
.It
The
.Ic _
command is different (in
.Nm mksh ,
it is the last argument command; in
.Xr vi 1
it goes to the start of the current line).
.It
The
.Ic /
and
.Ic G
commands move in the opposite direction to the
.Ic j
command.
.It
Commands which don't make sense in a single line editor are not available
(e.g. screen movement commands and
.Xr ex 1 Ns -style
colon
.Pq Ic \&:
commands).
.El
.Pp
Like
.Xr vi 1 ,
there are two modes:
.Dq insert
mode and
.Dq command
mode.
In insert mode, most characters are simply put in the buffer at the
current cursor position as they are typed; however, some characters are
treated specially.
In particular, the following characters are taken from current
.Xr tty 4
settings
(see
.Xr stty 1 )
and have their usual meaning (normal values are in parentheses): kill (\*(haU),
erase (\*(ha?), werase (\*(haW), eof (\*(haD), intr (\*(haC) and quit (\*(ha\e).
In addition to
the above, the following characters are also treated specially in insert mode:
.Bl -tag -width XJXXXXM
.It \*(haE
Command and file name enumeration (see below).
.It \*(haF
Command and file name completion (see below).
If used twice in a row, the
list of possible completions is displayed; if used a third time, the completion
is undone.
.It \*(haH
Erases previous character.
.It \*(haJ \*(Ba \*(haM
End of line.
The current line is read, parsed and executed by the shell.
.It \*(haV
Literal next.
The next character typed is not treated specially (can be used
to insert the characters being described here).
.It \*(haX
Command and file name expansion (see below).
.It Aq esc
Puts the editor in command mode (see below).
.It Aq tab
Optional file name and command completion (see
.Ic \*(haF
above), enabled with
.Ic set Fl o Ic vi\-tabcomplete .
.El
.Pp
In command mode, each character is interpreted as a command.
Characters that
don't correspond to commands, are illegal combinations of commands, or are
commands that can't be carried out, all cause beeps.
In the following command descriptions, an
.Op Ar n
indicates the command may be prefixed by a number (e.g.\&
.Ic 10l
moves right 10 characters); if no number prefix is used,
.Ar n
is assumed to be 1 unless otherwise specified.
The term
.Dq current position
refers to the position between the cursor and the character preceding the
cursor.
A
.Dq word
is a sequence of letters, digits and underscore characters or a sequence of
non-letter, non-digit, non-underscore and non-whitespace characters (e.g.\&
.Dq Li ab2*&\*(ha
contains two words) and a
.Dq big-word
is a sequence of non-whitespace characters.
.Pp
Special
.Nm
vi commands:
.Pp
The following commands are not in, or are different from, the normal vi file
editor:
.Bl -tag -width 10n
.It Xo
.Oo Ar n Oc Ns _
.Xc
Insert a space followed by the
.Ar n Ns th
big-word from the last command in the history at the current position and enter
insert mode; if
.Ar n
is not specified, the last word is inserted.
.It #
Insert the comment character
.Pq Ql #
at the start of the current line and return the line to the shell (equivalent
to
.Ic I#\*(haJ ) .
.It Xo
.Oo Ar n Oc Ns g
.Xc
Like
.Ic G ,
except if
.Ar n
is not specified, it goes to the most recent remembered line.
.It Xo
.Oo Ar n Oc Ns v
.Xc
Edit line
.Ar n
using the
.Xr vi 1
editor; if
.Ar n
is not specified, the current line is edited.
The actual command executed is
.Ic fc \-e ${VISUAL:\-${EDITOR:\-vi}} Ar n .
.It * and \*(haX
Command or file name expansion is applied to the current big-word (with an
appended
.Ql *
if the word contains no file globbing characters) \*(en the big-word is replaced
with the resulting words.
If the current big-word is the first on the line
or follows one of the characters
.Ql \&; ,
.Ql \*(Ba ,
.Ql & ,
.Ql \&(
or
.Ql \&)
and does not contain a slash
.Pq Ql / ,
then command expansion is done; otherwise file name expansion is done.
Command expansion will match the big-word against all aliases, functions and
built-in commands as well as any executable files found by searching the
directories in the
.Ev PATH
parameter.
File name expansion matches the big-word against the files in the
current directory.
After expansion, the cursor is placed just past the last
word and the editor is in insert mode.
.It Xo
.Oo Ar n Oc Ns \e ,
.Oo Ar n Oc Ns \*(haF ,
.Oo Ar n Oc Ns Aq tab ,
.No and
.Oo Ar n Oc Ns Aq esc
.Xc
Command/file name completion.
Replace the current big-word with the
longest unique match obtained after performing command and file name expansion.
.Aq tab
is only recognised if the
.Ic vi\-tabcomplete
option is set, while
.Aq esc
is only recognised if the
.Ic vi\-esccomplete
option is set (see
.Ic set Fl o ) .
If
.Ar n
is specified, the
.Ar n Ns th
possible completion is selected (as reported by the command/file name
enumeration command).
.It = and \*(haE
Command/file name enumeration.
List all the commands or files that match the current big-word.
.It \*(haV
Display the version of
.Nm mksh .
The current edit buffer is restored as soon as a key is pressed.
The restoring keypress is ignored.
.It @ Ns Ar c
Macro expansion.
Execute the commands found in the alias
.Ar c .
.El
.Pp
Intra-line movement commands:
.Bl -tag -width Ds
.It Xo
.Oo Ar n Oc Ns h and
.Oo Ar n Oc Ns \*(haH
.Xc
Move left
.Ar n
characters.
.It Xo
.Oo Ar n Oc Ns l and
.Oo Ar n Oc Ns Aq space
.Xc
Move right
.Ar n
characters.
.It 0
Move to column 0.
.It \*(ha
Move to the first non-whitespace character.
.It Xo
.Oo Ar n Oc Ns \*(Ba
.Xc
Move to column
.Ar n .
.It $
Move to the last character.
.It Xo
.Oo Ar n Oc Ns b
.Xc
Move back
.Ar n
words.
.It Xo
.Oo Ar n Oc Ns B
.Xc
Move back
.Ar n
big-words.
.It Xo
.Oo Ar n Oc Ns e
.Xc
Move forward to the end of the word,
.Ar n
times.
.It Xo
.Oo Ar n Oc Ns E
.Xc
Move forward to the end of the big-word,
.Ar n
times.
.It Xo
.Oo Ar n Oc Ns w
.Xc
Move forward
.Ar n
words.
.It Xo
.Oo Ar n Oc Ns W
.Xc
Move forward
.Ar n
big-words.
.It %
Find match.
The editor looks forward for the nearest parenthesis, bracket or
brace and then moves the cursor to the matching parenthesis, bracket or brace.
.It Xo
.Oo Ar n Oc Ns f Ns Ar c
.Xc
Move forward to the
.Ar n Ns th
occurrence of the character
.Ar c .
.It Xo
.Oo Ar n Oc Ns F Ns Ar c
.Xc
Move backward to the
.Ar n Ns th
occurrence of the character
.Ar c .
.It Xo
.Oo Ar n Oc Ns t Ns Ar c
.Xc
Move forward to just before the
.Ar n Ns th
occurrence of the character
.Ar c .
.It Xo
.Oo Ar n Oc Ns T Ns Ar c
.Xc
Move backward to just before the
.Ar n Ns th
occurrence of the character
.Ar c .
.It Xo
.Oo Ar n Oc Ns \&;
.Xc
Repeats the last
.Ic f , F , t
or
.Ic T
command.
.It Xo
.Oo Ar n Oc Ns \&,
.Xc
Repeats the last
.Ic f , F , t
or
.Ic T
command, but moves in the opposite direction.
.El
.Pp
Inter-line movement commands:
.Bl -tag -width Ds
.It Xo
.Oo Ar n Oc Ns j ,
.Oo Ar n Oc Ns + ,
.No and
.Oo Ar n Oc Ns \*(haN
.Xc
Move to the
.Ar n Ns th
next line in the history.
.It Xo
.Oo Ar n Oc Ns k ,
.Oo Ar n Oc Ns \- ,
.No and
.Oo Ar n Oc Ns \*(haP
.Xc
Move to the
.Ar n Ns th
previous line in the history.
.It Xo
.Oo Ar n Oc Ns G
.Xc
Move to line
.Ar n
in the history; if
.Ar n
is not specified, the number of the first remembered line is used.
.It Xo
.Oo Ar n Oc Ns g
.Xc
Like
.Ic G ,
except if
.Ar n
is not specified, it goes to the most recent remembered line.
.It Xo
.Oo Ar n Oc Ns / Ns Ar string
.Xc
Search backward through the history for the
.Ar n Ns th
line containing
.Ar string ;
if
.Ar string
starts with
.Ql \*(ha ,
the remainder of the string must appear at the start of the history line for
it to match.
.It Xo
.Oo Ar n Oc Ns \&? Ns Ar string
.Xc
Same as
.Ic / ,
except it searches forward through the history.
.It Xo
.Oo Ar n Oc Ns n
.Xc
Search for the
.Ar n Ns th
occurrence of the last search string;
the direction of the search is the same as the last search.
.It Xo
.Oo Ar n Oc Ns N
.Xc
Search for the
.Ar n Ns th
occurrence of the last search string;
the direction of the search is the opposite of the last search.
.It Ar ANSI-CurUp , PC-PgUp
Take the characters from the beginning of the line to the current
cursor position as search string and do a backwards history search
for lines beginning with this string; keep the cursor position.
This works only in insert mode and keeps it enabled.
.El
.Pp
Edit commands
.Bl -tag -width Ds
.It Xo
.Oo Ar n Oc Ns a
.Xc
Append text
.Ar n
times; goes into insert mode just after the current position.
The append is
only replicated if command mode is re-entered i.e.\&
.Aq esc
is used.
.It Xo
.Oo Ar n Oc Ns A
.Xc
Same as
.Ic a ,
except it appends at the end of the line.
.It Xo
.Oo Ar n Oc Ns i
.Xc
Insert text
.Ar n
times; goes into insert mode at the current position.
The insertion is only
replicated if command mode is re-entered i.e.\&
.Aq esc
is used.
.It Xo
.Oo Ar n Oc Ns I
.Xc
Same as
.Ic i ,
except the insertion is done just before the first non-blank character.
.It Xo
.Oo Ar n Oc Ns s
.Xc
Substitute the next
.Ar n
characters (i.e. delete the characters and go into insert mode).
.It S
Substitute whole line.
All characters from the first non-blank character to the
end of the line are deleted and insert mode is entered.
.It Xo
.Oo Ar n Oc Ns c Ns Ar move-cmd
.Xc
Change from the current position to the position resulting from
.Ar n move-cmd Ns s
(i.e. delete the indicated region and go into insert mode); if
.Ar move-cmd
is
.Ic c ,
the line starting from the first non-blank character is changed.
.It C
Change from the current position to the end of the line (i.e. delete to the
end of the line and go into insert mode).
.It Xo
.Oo Ar n Oc Ns x
.Xc
Delete the next
.Ar n
characters.
.It Xo
.Oo Ar n Oc Ns X
.Xc
Delete the previous
.Ar n
characters.
.It D
Delete to the end of the line.
.It Xo
.Oo Ar n Oc Ns d Ns Ar move-cmd
.Xc
Delete from the current position to the position resulting from
.Ar n move-cmd Ns s ;
.Ar move-cmd
is a movement command (see above) or
.Ic d ,
in which case the current line is deleted.
.It Xo
.Oo Ar n Oc Ns r Ns Ar c
.Xc
Replace the next
.Ar n
characters with the character
.Ar c .
.It Xo
.Oo Ar n Oc Ns R
.Xc
Replace.
Enter insert mode but overwrite existing characters instead of
inserting before existing characters.
The replacement is repeated
.Ar n
times.
.It Xo
.Oo Ar n Oc Ns \*(TI
.Xc
Change the case of the next
.Ar n
characters.
.It Xo
.Oo Ar n Oc Ns y Ns Ar move-cmd
.Xc
Yank from the current position to the position resulting from
.Ar n move-cmd Ns s
into the yank buffer; if
.Ar move-cmd
is
.Ic y ,
the whole line is yanked.
.It Y
Yank from the current position to the end of the line.
.It Xo
.Oo Ar n Oc Ns p
.Xc
Paste the contents of the yank buffer just after the current position,
.Ar n
times.
.It Xo
.Oo Ar n Oc Ns P
.Xc
Same as
.Ic p ,
except the buffer is pasted at the current position.
.El
.Pp
Miscellaneous vi commands
.Bl -tag -width Ds
.It \*(haJ and \*(haM
The current line is read, parsed and executed by the shell.
.It \*(haL and \*(haR
Redraw the current line.
.It Xo
.Oo Ar n Oc Ns \&.
.Xc
Redo the last edit command
.Ar n
times.
.It u
Undo the last edit command.
.It U
Undo all changes that have been made to the current line.
.It PC Home, End, Del and cursor keys
They move as expected, both in insert and command mode.
.It Ar intr No and Ar quit
The interrupt and quit terminal characters cause the current line to be
removed to the history and a new prompt to be printed.
.El
.Sh FILES
.Bl -tag -width XetcXsuid_profile -compact
.It Pa \*(TI/.mkshrc
User mkshrc profile (non-privileged interactive shells); see
.Sx Startup files.
The location can be changed at compile time (for embedded systems);
AOSP Android builds use
.Pa /system/etc/mkshrc .
.It Pa \*(TI/.profile
User profile (non-privileged login shells); see
.Sx Startup files
near the top of this manual.
.It Pa /etc/profile
System profile (login shells); see
.Sx Startup files.
.It Pa /etc/shells
Shell database.
.It Pa /etc/suid_profile
Suid profile (privileged shells); see
.Sx Startup files.
.El
.Pp
Note: On Android,
.Pa /system/etc/
contains the system and suid profile.
.Sh SEE ALSO
.Xr awk 1 ,
.Xr cat 1 ,
.Xr ed 1 ,
.Xr getopt 1 ,
.Xr lksh 1 ,
.Xr sed 1 ,
.Xr sh 1 ,
.Xr stty 1 ,
.Xr dup 2 ,
.Xr execve 2 ,
.Xr getgid 2 ,
.Xr getuid 2 ,
.Xr mknod 2 ,
.Xr mkfifo 2 ,
.Xr open 2 ,
.Xr pipe 2 ,
.Xr rename 2 ,
.Xr wait 2 ,
.Xr getopt 3 ,
.Xr nl_langinfo 3 ,
.Xr setlocale 3 ,
.Xr signal 3 ,
.Xr system 3 ,
.Xr tty 4 ,
.Xr shells 5 ,
.Xr environ 7 ,
.Xr script 7 ,
.Xr utf\-8 7 ,
.Xr mknod 8
.Pp
.Pa http://www.mirbsd.org/ksh\-chan.htm
.Rs
.%A Morris Bolsky
.%B "The KornShell Command and Programming Language"
.%D 1989
.%I "Prentice Hall PTR"
.%P "xvi\ +\ 356 pages"
.%O "ISBN 978\-0\-13\-516972\-8 (0\-13\-516972\-0)"
.Re
.Rs
.%A Morris I. Bolsky
.%A David G. Korn
.%B "The New KornShell Command and Programming Language (2nd Edition)"
.%D 1995
.%I "Prentice Hall PTR"
.%P "xvi\ +\ 400 pages"
.%O "ISBN 978\-0\-13\-182700\-4 (0\-13\-182700\-6)"
.Re
.Rs
.%A Stephen G. Kochan
.%A Patrick H. Wood
.%B "\\*(tNUNIX\\*(sP Shell Programming"
.%V "3rd Edition"
.%D 2003
.%I "Sams"
.%P "xiii\ +\ 437 pages"
.%O "ISBN 978\-0\-672\-32490\-1 (0\-672\-32490\-3)"
.Re
.Rs
.%A "IEEE Inc."
.%T "\\*(tNIEEE\\*(sP Standard for Information Technology \*(en Portable Operating System Interface (POSIX)"
.%V "Part 2: Shell and Utilities"
.%D 1993
.%I "IEEE Press"
.%P "xvii\ +\ 1195 pages"
.%O "ISBN 978\-1\-55937\-255\-8 (1\-55937\-255\-9)"
.Re
.Rs
.%A Bill Rosenblatt
.%B "Learning the Korn Shell"
.%D 1993
.%I "O'Reilly"
.%P "360 pages"
.%O "ISBN 978\-1\-56592\-054\-5 (1\-56592\-054\-6)"
.Re
.Rs
.%A Bill Rosenblatt
.%A Arnold Robbins
.%B "Learning the Korn Shell, Second Edition"
.%D 2002
.%I "O'Reilly"
.%P "432 pages"
.%O "ISBN 978\-0\-596\-00195\-7 (0\-596\-00195\-9)"
.Re
.Rs
.%A Barry Rosenberg
.%B "KornShell Programming Tutorial"
.%D 1991
.%I "Addison-Wesley Professional"
.%P "xxi\ +\ 324 pages"
.%O "ISBN 978\-0\-201\-56324\-5 (0\-201\-56324\-X)"
.Re
.Sh AUTHORS
.An -nosplit
.Nm "The MirBSD Korn Shell"
is developed by
.An mirabilos Aq Mt m@mirbsd.org
as part of The MirOS Project.
This shell is based on the public domain 7th edition Bourne shell clone by
.An Charles Forsyth ,
who kindly agreed to, in countries where the Public Domain status of the work
may not be valid, grant a copyright licence to the general public to deal in
the work without restriction and permission to sublicence derivatives under
the terms of any (OSI approved) Open Source licence,
and parts of the BRL shell by
.An Doug A. Gwyn ,
.An Doug Kingston ,
.An Ron Natalie ,
.An Arnold Robbins ,
.An Lou Salkind
and others.
The first release of
.Nm pdksh
was created by
.An Eric Gisin ,
and it was subsequently maintained by
.An John R. MacMillan ,
.An Simon J. Gerraty
and
.An Michael Rendell .
The effort of several projects, such as Debian and OpenBSD, and other
contributors including our users, to improve the shell is appreciated.
See the documentation, website and source code (CVS) for details.
.Pp
.Nm mksh\-os2
is developed by
.An KO Myung-Hun Aq Mt komh@chollian.net .
.Pp
.Nm mksh\-w32
is developed by
.An Michael Langguth Aq Mt lan@scalaris.com .
.Pp
.Nm mksh Ns / Ns Tn z/OS
is contributed by
.An Daniel Richard G. Aq Mt skunk@iSKUNK.ORG .
.Pp
The BSD daemon is Copyright \(co Marshall Kirk McKusick.
The complete legalese is at:
.Pa http://www.mirbsd.org/TaC\-mksh.txt
.\"
.\" This boils down to: feel free to use mksh.ico as application icon
.\" or shortcut for mksh or mksh/Win32 or OS/2; distro patches are ok
.\" (but we request they amend $KSH_VERSION when modifying mksh).
.\" Authors are Marshall Kirk McKusick (UCB), Rick Collette (ekkoBSD),
.\" mirabilos, Benny Siegert (MirBSD), Michael Langguth (mksh/Win32),
.\" KO Myung-Hun (mksh for OS/2).
.\"
.\" As far as MirBSD is concerned, the files themselves are free
.\" to modification and distribution under BSD/MirOS Licence, the
.\" restriction on use stems only from trademark law's requirement
.\" to protect it or lose it, which McKusick almost did.
.\"
.Sh CAVEATS
.Nm mksh
provides a consistent 32-bit integer arithmetic implementation, both
signed and unsigned, with sign of the result of a remainder operation
and wraparound defined, even (defying POSIX) on 36-bit and 64-bit systems.
.Pp
.Nm mksh
provides a consistent, clear interface normally.
This may deviate from POSIX in historic or opinionated places.
.Ic set Fl o Ic posix
(see
.Sx POSIX mode
for details)
will cause the shell to behave more conformant.
.Pp
For the purpose of
.Tn POSIX ,
.Nm mksh
supports only the
.Dq C
locale.
.Nm mksh Ns 's
.Ic utf8\-mode
.Em must
be disabled in POSIX mode, and it
only supports the BMP (Basic Multilingual Plane) of UCS and maps
raw octets into the U+EF80..U+EFFF wide character range; compare
.Sx Arithmetic expressions .
The following
.Tn POSIX
.Nm sh Ns -compatible
code toggles the
.Ic utf8\-mode
option dependent on the current
.Tn POSIX
locale for mksh to allow using the UTF-8 mode, within the constraints
outlined above, in code portable across various shell implementations:
.Bd -literal -offset indent
case ${KSH_VERSION:\-} in
*MIRBSD\ KSH*\*(Ba*LEGACY\ KSH*)
	case ${LC_ALL:\-${LC_CTYPE:\-${LANG:\-}}} in
	*[Uu][Tt][Ff]8*\*(Ba*[Uu][Tt][Ff]\-8*) set \-U ;;
	*) set +U ;;
	esac ;;
esac
.Ed
In near future, (UTF-8) locale tracking will be implemented though.
.Pp
See also the FAQ below.
.Sh BUGS
Suspending (using \*(haZ) pipelines like the one below will only suspend
the currently running part of the pipeline; in this example,
.Dq Li fubar
is immediately printed on suspension (but not later after an
.Ic fg ) .
.Bd -literal -offset indent
$ /bin/sleep 666 && echo fubar
.Ed
.Pp
The truncation process involved when changing
.Ev HISTFILE
does not free old history entries (leaks memory) and leaks
old entries into the new history if their line numbers are
not overwritten by same-number entries from the persistent
history file; truncating the on-disc file to
.Ev HISTSIZE
lines has always been broken and prone to history file corruption
when multiple shells are accessing the file; the rollover process
for the in-memory portion of the history is slow, should use
.Xr memmove 3 .
.Pp
This document attempts to describe
.Nm mksh\ R57
and up,
.\" with vendor patches from insert-your-name-here,
compiled without any options impacting functionality, such as
.Dv MKSH_SMALL ,
when not called as
.Pa /bin/sh
which, on some systems only, enables
.Ic set Fl o Ic posix
or
.Ic set Fl o Ic sh
automatically (whose behaviour differs across targets),
for an operating environment supporting all of its advanced needs.
.Pp
Please report bugs in
.Nm
to the public development mailing list at
.Aq Mt miros\-mksh@mirbsd.org
(please note the EU-DSGVO/GDPR notice on
.Pa http://www.mirbsd.org/rss.htm#lists
and in the SMTP banner!) or in the
.Li \&#\&!/bin/mksh
.Pq or Li \&#ksh
IRC channel at
.Pa irc.freenode.net
.Pq Port 6697 SSL, 6667 unencrypted ,
or at:
.Pa https://launchpad.net/mksh
.Sh FREQUENTLY ASKED QUESTIONS
This FAQ attempts to document some of the questions users of
.Nm
or readers of this manual page may encounter.
.Ss I'm an Android user, so what's mksh?
.Nm mksh
is a
.Ux
shell / command interpreter, similar to
.Nm COMMAND.COM
or
.Nm CMD.EXE ,
which has been included with
.Tn Android Open Source Project
for a while now.
Basically, it's a program that runs in a terminal (console window),
takes user input and runs commands or scripts, which it can also
be asked to do by other programs, even in the background.
Any privilege pop-ups you might be encountering are thus not
.Nm mksh
issues but questions by some other program utilising it.
.Ss "I'm an OS/2 user, what do I need to know?"
Unlike the native command prompt, the current working directory is,
for security reasons common on Unix systems which the shell is designed for,
not in the search path at all; if you really need this, run the command
.Li PATH=.$PATHSEP$PATH
or add that to a suitable initialisation file.
.Pp
There are two different newline modes for mksh-os2: standard (Unix) mode,
in which only LF (0A hex) is supported as line separator, and "textmode",
which also accepts ASCII newlines (CR+LF), like most other tools on OS/2,
but creating an incompatibility with standard
.Nm .
If you compiled mksh from source, you will get the standard Unix mode unless
.Fl T
is added during compilation; you will most likely have gotten this shell
through komh's port on Hobbes, or from his OS/2 Factory on eComStation
Korea, which uses "textmode", though.
Most OS/2 users will want to use "textmode" unless they need absolute
compatibility with Unix
.Nm .
.Ss "How do I start mksh on a specific terminal?"
Normally:
.Dl mksh \-T/dev/tty2
.Pp
However, if you want for it to return (e.g. for an embedded
system rescue shell), use this on your real console device instead:
.Dl mksh \-T!/dev/ttyACM0
.Pp
.Nm
can also daemonise (send to the background):
.Dl mksh \-T\- \-c \*(aqexec cdio lock\*(aq
.Ss "POSIX says..."
Run the shell in POSIX mode (and possibly
.Nm lksh
instead of
.Nm mksh ) :
.Dl set \-o posix
.Ss "My prompt from <some other shell> does not work!"
Contact us on the mailing list or on IRC, we'll convert it for you.
.Ss "Something is going wrong with my while...read loop"
Most likely, you've encountered the problem in which the shell runs
all parts of a pipeline as subshell.
The inner loop will be executed in a subshell and variable changes
cannot be propagated if run in a pipeline:
.Bd -literal -offset indent
bar \*(Ba baz \*(Ba while read foo; do ...; done
.Ed
.Pp
Note that
.Ic exit
in the inner loop will only exit the subshell and not the original shell.
Likewise, if the code is inside a function,
.Ic return
in the inner loop will only exit the subshell and won't terminate the function.
.Pp
Use co-processes instead:
.Bd -literal -offset indent
bar \*(Ba baz \*(Ba&
while read \-p foo; do ...; done
exec 3\*(Gt&p; exec 3\*(Gt&\-
.Ed
.Pp
If
.Ic read
is run in a loop such as
.Ic while read foo; do ...; done
then leading whitespace will be removed (IFS) and backslashes processed.
You might want to use
.Ic while IFS= read \-r foo; do ...; done
for pristine I/O.
Similarly, when using the
.Fl a
option, use of the
.Fl r
option might be prudent
.Pq Dq Li read \-raN\-1 arr \*(Ltfile ;
the same applies for NUL-terminated lines:
.Bd -literal -offset indent
find . \-type f \-print0 \*(Ba& \e
    while IFS= read \-d \*(aq\*(aq \-pr filename; do
	print \-r \-\- "found \*(Lt${filename#./}\*(Gt"
done
.Ed
.Pp
.Ss "What differences in function-local scopes are there?"
.Nm
has a different scope model from
.At
.Nm ksh ,
which leads to subtle differences in semantics for identical builtins.
This can cause issues with a
.Ic nameref
to suddenly point to a local variable by accident.
.Pp
.Tn GNU
.Nm bash
allows unsetting local variables; in
.Nm ,
doing so in a function allows back access to the global variable
(actually the one in the next scope up) with the same name.
The following code, when run before the function definitions, changes
the behaviour of
.Ic unset
to behave like other shells (the alias can be removed after the definitions):
.Bd -literal -offset indent
case ${KSH_VERSION:\-} in
*MIRBSD\ KSH*\*(Ba*LEGACY\ KSH*)
	function unset_compat {
		\e\ebuiltin typeset unset_compat_x

		for unset_compat_x in "$@"; do
			eval "\e\e\e\ebuiltin unset $unset_compat_x[*]"
		done
	}
	\e\ebuiltin alias unset=unset_compat
	;;
esac
.Ed
.Pp
When a local variable is created (e.g. using
.Ic local ,
.Ic typeset ,
.Ic integer ,
.Ic \e\ebuiltin typeset )
it does not, like in other shells, inherit the value from the global
(next scope up) variable with the same name; it is rather created
without any value (unset but defined).
.Ss "I get an error in this regex comparison"
Use extglobs instead of regexes:
.Dl "[[ foo =~ (foo\*(Babar).*baz ]]	# becomes"
.Dl "[[ foo = *@(foo\*(Babar)*baz* ]]	# instead"
.Ss "Are there any extensions to avoid?"
.Tn GNU
.Nm bash
supports
.Dq Li &\*(Gt
.Pq and Dq Li \*(Ba&
to redirect both stdout and stderr in one go, but this breaks POSIX
and Korn Shell syntax; use POSIX redirections instead:
.Dl "foo \*(Ba& bar \*(Ba& baz &\*(Gtlog			     # GNU bash"
.Dl "foo 2\*(Gt&1 \*(Ba bar 2\*(Gt&1 \*(Ba baz \*(Gtlog 2\*(Gt&1	# POSIX"
.Ss "\*(haL (Ctrl-L) does not clear the screen"
Use \*(ha[\*(haL (Escape+Ctrl-L) or rebind it:
.Dl bind \*(aq\*(haL=clear-screen\*(aq
.Ss "\*(haU (Ctrl-U) clears the entire line"
If it should only delete the line up to the cursor, use:
.Dl bind \-m \*(haU=\*(aq\*(ha[0\*(haK\*(aq
.Ss "Cursor Up behaves differently from zsh"
Some shells make Cursor Up search in the history only for
commands starting with what was already entered.
.Nm
separates the shortcuts: Cursor Up goes up one command
and PgUp searches the history as described above.
.Ss "My question is not answered here!"
Check
.Pa http://www.mirbsd.org/mksh\-faq.htm
which contains a collection of frequently asked questions about
.Nm
in general, for packagers, etc. while these above are in user scope.