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
|
.\" es.1 -- es manual page ($Revision: 1.1.1.1 $)
.\" macros stolen from rc.1
.\"-------
.\" Man page portability notes
.\"
.\" These are some notes on conventions to maintain for greatest
.\" portability of this man page to various other versions of
.\" nroff.
.\"
.\" When you want a \ to appear in the output, use \e in the man page.
.\" (NOTE this comes up in the rc grammar, where to print out '\n' the
.\" man page must contain '\en'.)
.\"
.\" Evidently not all versions of nroff allow the omission of the
.\" terminal " on a macro argument. Thus what could be written
.\"
.\" .Cr "exec >[2] err.out
.\"
.\" in true nroffs must be written
.\"
.\" .Cr "exec >[2] err.out"
.\"
.\" instead.
.\"
.\" Use symbolic font names (e.g. R, I, B) instead of the standard
.\" font positions 1, 2, 3. Note that for Xf to work the standard
.\" font names must be single characters.
.\"
.\" Not all man macros have the RS and RE requests (I altered the Ds
.\" and De macros and the calls to Ds accordingly).
.\"
.\" Thanks to Michael Haardt (u31b3hs@cip-s01.informatik.rwth-aachen.de)
.\" for pointing out these problems.
.\"
.\" Note that sentences should end at the end of a line. nroff and
.\" troff will supply the correct intersentence spacing, but only if
.\" the sentences end at the end of a line. Explicit spaces, if given,
.\" are apparently honored and the normal intersentence spacing is
.\" supressed.
.\"
.\" DaviD W. Sanderson
.\"-------
.\" Dd distance to space vertically before a "display"
.\" These are what n/troff use for interparagraph distance
.\"-------
.if t .nr Dd .4v
.if n .nr Dd 1v
.\"-------
.\" Ds begin a display, indented .5 inches from the surrounding text.
.\"
.\" Note that uses of Ds and De may NOT be nested.
.\"-------
.de Ds
.\" .RS \\$1
.sp \\n(Ddu
.in +0.5i
.nf
..
.\"-------
.\" De end a display (no trailing vertical spacing)
.\"-------
.de De
.fi
.in
.\" .RE
..
.\"-------
.\" I stole the Xf macro from the -man macros on my machine (originally
.\" "}S", I renamed it so that it won't conflict).
.\"-------
.\" Set Cf to the name of the constant width font.
.\" It will be "C" or "(CW", typically.
.\" NOTEZ BIEN the lines defining Cf must have no trailing white space:
.\"-------
.if t .ds Cf C
.if n .ds Cf R
.\"-------
.\" Rc - Alternate Roman and Courier
.\"-------
.de Rc
.Xf R \\*(Cf \& "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"
..
.\"-------
.\" Ic - Alternate Italic and Courier
.\"-------
.de Ic
.Xf I \\*(Cf \& "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"
..
.\"-------
.\" Bc - Alternate Bold and Courier
.\"-------
.de Bc
.Xf B \\*(Cf \& "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"
..
.\"-------
.\" Cr - Alternate Courier and Roman
.\"-------
.de Cr
.Xf \\*(Cf R \& "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"
..
.\"-------
.\" Ci - Alternate Courier and Italic
.\"-------
.de Ci
.Xf \\*(Cf I \& "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"
..
.\"-------
.\" Cb - Alternate Courier and Bold
.\"-------
.de Cb
.Xf \\*(Cf B \& "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6"
..
.\"-------
.\" Xf - Alternate fonts
.\"
.\" \$1 - first font
.\" \$2 - second font
.\" \$3 - desired word with embedded font changes, built up by recursion
.\" \$4 - text for first font
.\" \$5 - \$9 - remaining args
.\"
.\" Every time we are called:
.\"
.\" If there is something in \$4
.\" then Call ourself with the fonts switched,
.\" with a new word made of the current word (\$3) and \$4
.\" rendered in the first font,
.\" and with the remaining args following \$4.
.\" else We are done recursing. \$3 holds the desired output
.\" word. We emit \$3, change to Roman font, and restore
.\" the point size to the default.
.\" fi
.\"
.\" Use Xi to add a little bit of space after italic text.
.\"-------
.de Xf
.ds Xi
.\"-------
.\" I used to test for the italic font both by its font position
.\" and its name. Now just test by its name.
.\"
.\" .if "\\$1"2" .if !"\\$5"" .ds Xi \^
.\"-------
.if "\\$1"I" .if !"\\$5"" .ds Xi \^
.\"-------
.\" This is my original code to deal with the recursion.
.\" Evidently some nroffs can't deal with it.
.\"-------
.\" .ie !"\\$4"" \{\
.\" . Xf \\$2 \\$1 "\\$3\\f\\$1\\$4\\*(Xi" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
.\" .\}
.\" .el \{\\$3
.\" . ft R \" Restore the default font, since we don't know
.\" . \" what the last font change was.
.\" . ps 10 \" Restore the default point size, since it might
.\" . \" have been changed by an argument to this macro.
.\" .\}
.\"-------
.\" Here is more portable (though less pretty) code to deal with
.\" the recursion.
.\"-------
.if !"\\$4"" .Xf \\$2 \\$1 "\\$3\\f\\$1\\$4\\*(Xi" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
.if "\\$4"" \\$3\fR\s10
..
.\"-------
.\" IS, IE -- sublist begin and end
.\"-------
.de IS
.ie \n(.g .RS
.el \{\
.nr )R +7m
.nr )P -.5v
.sp .7v \}
..
.de IE
.ie \n(.g .RE
.el \{\
.nr )R -7m
.nr )P +.5v
.sp .4v \}
..
.TH ES 1 "5 March 1992"
.SH NAME
es \- extensible shell
.SH SYNOPSIS
.B es
.RB [ \-silevxnpo ]
.RB [ \-c
.IR command
|
.IR file ]
.RI [ arguments ]
.SH DESCRIPTION
.I Es
is a command interpreter and programming language which combines
the features of other Unix shells and the features of a functional
programming language such as Scheme.
The syntax is derived from
.IR rc (1).
.I Es
is intended for use both as an interactive shell and a programming
language for scripts.
.PP
.I Es
is an extremely customizable language.
The semantics can be altered radically by redefining functions that
are called to implement internal operations.
This manual page describes the default, initial configuration.
See the section entitled
.B "Hook Functions"
for details on entry points which can be redefined to give
the shell extended semantics.
.SH LANGUAGE
.I Es
is an interpreter which reads commands and executes them.
The simplest form of command in
.I es
is a sequence of words separated by white space (space and tab) characters.
A word is either a string or a program fragment (see below).
The first word is the command to be executed; the remaining
words are passed as arguments to that command.
If the first word is a string, it is a interpreted as the
name of a program or shell function to run.
If the name is the name of a shell function, that function
is executed.
Otherwise, the name is used as the name of an executable file.
If the name begins with
.Cr / ,
.Cr ./ ,
or
.Cr ../ ,
then it is used as the absolute path name of a file;
if not,
.I es
looks for an executable file in the directories named by
.Cr $path .
.PP
Commands are terminated by newline or semicolon
.Rc ( ; ).
A command may also be terminated by an ampersand
.Rc ( & ),
which causes the command to be run in the background:
the shell does not wait for the command
to finish before continuing execution.
Background processes have an implicit redirection of
.Cr /dev/null
as their standard input that may be overridden by an explicit redirection.
.SS Quoting
.IR Es
gives several characters special meaning;
special characters automatically terminate words.
The following characters, along with space, tab, and newline, are special:
.Ds
.Cr "# $ & \' ( ) ; < = > \e ^ \` { | }"
.De
.PP
The single quote
.Rc ( ' )
prevents special treatment of any character other than itself.
Any characters between single quotes, including newlines, backslashes,
and control characters, are treated as an uninterpreted string.
A quote character itself may be quoted by placing two quotes in a row.
A single quote character is therefore represented by the sequence
.Cr '''' .
The empty string is represented by
.Cr '' .
Thus:
.Ds
.Cr "echo 'What''s the plan, Stan?'"
.De
.PP
prints out
.Ds
.Cr "What's the plan, Stan?"
.De
.PP
The backslash
.Cr ( \e )
quotes the immediately following character, if it is
one of the special characters, except for newline.
In addition,
.IR es
recognizes backslash sequences similar to those used in C strings:
.IS
.TP
.Cr \ea
alert (bell)
.TP
.Cr \eb
backspace
.TP
.Cr \ee
escape
.TP
.Cr \ef
form-feed
.TP
.Cr \en
newline
.TP
.Cr \er
carriage return
.TP
.Cr \et
tab
.TP
.Ci \ex nn
hexadecimal character
.IR nn
.TP
.Ci \e nnn
octal character
.IR nnn
.IE
.SS Comments
The number sign
.Rc ( # )
begins a comment in
.IR es .
All characters up to but not including the next newline are ignored.
.SS "Line continuation"
A long logical line may be continued over several physical lines by
terminating each line (except the last) with a backslash
.Rc ( \e ).
The backslash-newline sequence is treated as a space.
Note that line continuation does not work in comments, where the backslash is
treated as part of the comment, and inside quoted strings, where the backslash
and newline are quoted.
.SS Lists
The primary data structure in
.IR es
is the list, which is a sequence of words.
Parentheses are used to group lists.
The empty list is represented by
.Cr "()" .
Lists have no hierarchical structure;
a list inside another list is expanded so that the
outer list contains all the elements of the inner list.
Thus, the following are all equivalent:
.Ds
.Cr "one two three"
.Cr "(one two three)"
.Cr "((one) () ((two three)))"
.De
.PP
Note that the null string,
.Cr "''" ,
and the empty list,
.Cr "()" ,
are two very
different things.
Assigning the null string to variable is a valid
operation, but it does not remove its definition.
.SS Concatenation
Two lists may be joined by the concatenation operator
.Rc ( ^ ).
A single word is a list of length one, so
.Ds
.Cr "echo foo^bar"
.De
.PP
produces the output
.Ds
.Cr foobar
.De
.PP
For lists of more than one element,
concatenation produces the cross (Cartesian) product of
the elements in both lists:
.Ds
.Cr "echo (a\- b\- c\-)^(1 2)"
.De
.PP
produces the output
.Ds
.Cr "a\-1 a\-2 b\-1 b\-2 c\-1 c\-2"
.De
.SS "Variables"
A list may be assigned to a variable, using the notation:
.Ds
.Ic var " = " list
.De
.PP
Any sequence of non-special characters, except a sequence including
only digits, may be used as a variable name.
.I Es
exports all user-defined variables into the environment unless
it is explicitly told not to.
.PP
The value of a variable is referenced with the notation:
.Ds
.Ci $ var
.De
.PP
Any variable which has not been assigned a value returns the empty list
when referenced.
In addition, multiple references are allowed:
.Ds
.Cr "a = foo"
.Cr "b = a"
.Cr "echo $$b"
.De
.PP
prints
.Ds
.Cr foo
.De
.PP
A variable's definition may also be removed by
assigning the empty list to a variable:
.Ds
.Ic var =
.De
.PP
Multiple variables may be assigned with a single assignment statment.
The left hand side of the assignment operation consists of a list of
variables which are assigned, one by one, to the values in the list
on the right hand side. If there are more variables than values in
the list, the empty list is assigned to the remaining variables.
If there are fewer variables than elements in the list, the last
variable is bound to all the remaining list values.
.PP
For example,
.Ds
.Cr "(a b) = 1 2 3"
.De
.PP
has the same effect as
.Ds
.Cr "a = 1"
.Cr "b = 2 3"
.Ds
.PP
and
.Ds
.Cr "(a b c) = 1 2"
.De
.PP
is the same as
.Ds
.Cr "a = 1"
.Cr "b = 2"
.Cr "c ="
.Ds
.PP
Note that when assigning values to more than one variable,
the list of variables must be enclosed in parentheses.
.PP
For ``free careting'' (see below) to work correctly,
.I es
must make certain assumptions
about what characters may appear in a variable name.
.I Es
assumes that a variable name consists only of alphanumeric characters,
percent
.Rc ( % ),
star
.Rc ( * ),
dash
.Rc ( - ),
and underscore
.Rc ( \|_\| ).
To reference a variable with other
characters in its name, quote the variable name.
Thus:
.Ds
.Cr "echo $'we$Ird\Variab!le'"
.De
.PP
A variable name produced by some complex operation,
such as concatenation, should be enclosed in parentheses:
.Ds
.Ci $( var )
.De
.PP
Thus:
.Ds
.Cr "Good\-Morning = Bonjour"
.Cr "Guten = Good"
.Cr "Morgen = Morning"
.Cr "echo $($Guten^\-^$Morgen)"
.De
.PP
prints
.Ds
.Cr "Bonjour"
.De
.PP
Each element of the list in parentheses is treated as an
independent variable and expanded separately.
Thus, given the above definitions,
.Ds
.Cr "echo $(Guten Morgen)"
.De
.PP
prints
.Ds
.Cr "Good Morning"
.De
.PP
To count the number of elements in a variable, use
.Ds
.Ci $# var
.De
.PP
This returns a single-element list with the number of elements in
.Ci $ var\fR.
.SS Subscripting
Variables may be indexed with the notation
.Ds
.Ci $ var ( n )
.De
.PP
where
.I n
is a list of integers or ranges.
Subscript indexes are based at one.
The list of subscripts need
not be in order or even unique.
Thus, if
.Ds
.Cr "a = one two three"
.De
.PP
then
.Ds
.Cr "echo $a(3 3 3)"
.De
.PP
prints
.Ds
.Cr "three three three"
.De
.PP
Subscript indices which refer to nonexistent elements
expand to the empty list. Thus, given the definition above
.Ds
.Cr "echo $a(3 1 4 1 5 9 2 6 5)"
.De
.PP
prints
.Ds
.Cr "three one one two"
.De
.PP
Subscript ranges are of the form
.Ic lo ... hi
and refer to all the elements between
.I lo
and
.IR hi .
If
.I lo
is omitted, then
.Cr 1
is used as a default value; if
.I hi
is omitted, the length of the list is used.
Thus
.Ds
.Cr "* = $*(2 ...)"
.De
.PP
removes the first element of
.Cr * ,
similar to the effect of
.Cr shift
in
.IR rc (1)
or
.IR sh (1).
.PP
The notation
.Ci "$" n\fR,
where
.I n
is an integer, is a shorthand for
.Ci $*( n )\fR.
Thus,
.IR es 's
arguments may be referred to as
.Cr "$1" ,
.Cr "$2" ,
and so on.
.PP
Note that the list of subscripts may be given by any
.IR es
expression, so
.Ds
.Cr "$var(\`{awk 'BEGIN{for(i=1;i<=10;i++)print i;exit }'})"
.De
.PP
returns the first 10 elements of
.Cr $var .
.SS "Free Carets"
.I Es
inserts carets (concatenation operators) for free in certain situations,
in order to save some typing on the user's behalf.
For example, the following are all equivalent:
.Ds
.Cr "cc \-O \-g \-c malloc.c alloca.c"
.Cr "cc \-^(O g c) (malloc alloca)^.c"
.Cr "opts=O g c; files=malloc alloca; cc \-$opts $files.c"
.De
.PP
.I Es
inserts a free-caret between the
.Rc `` \- ''
and
.Cr "$opts" ,
as well
as between
.Cr $files
and
.Cr ".c" .
The rule for free carets is as follows:
if a word or keyword is immediately
followed by another word, keyword, dollar-sign or
backquote without any intervening spaces, then
.I es
inserts a caret between them.
.SS "Flattened Lists"
To create a single-element list from a multi-element list,
with the components space-separated, use
.Ds
.Ci $^ var
.De
.PP
Flattening is useful when the normal list concatenation rules need to be
bypassed.
For example, to append a single period at the end of
.Cr $path ,
use:
.Ds
.Cr "echo $^path."
.De
.SS "Wildcard Expansion"
.I Es
expands wildcards in filenames if possible.
When the characters
.Cr "*" ,
.Cr [
or
.Cr ?
occur in an argument or command,
.I es
looks at the
argument as a pattern for matching against files.
(Contrary to the behavior some other shells exhibit,
.I es
will only perform pattern matching if a metacharacter occurs unquoted and
literally in the input.
Thus,
.Ds
.Cr "foo = '*'"
.Cr "echo $foo"
.De
.PP
will always echo just a star.
In order for non-literal metacharacters to be expanded, an
.Cr eval
statement must be used in order to rescan the input.)
Pattern matching occurs according to the following rules:
a
.Cr "*"
matches any number (including zero) of
characters.
A
.Cr ?
matches any single character, and a
.Cr [
followed by a
number of characters followed by a
.Cr ]
matches a single character in that
class.
The rules for character class matching are the same as those for
.IR ed (1),
with the exception that character class negation is achieved
with the tilde
.Rc ( ~ ),
not the caret
.Rc ( ^ ),
since the caret already means
something else in
.IR es .
The filename component separator, slash
.Rc ( / ),
must appear explicitly in patterns.
.Cr "*"
and
.Cr ?
do not match a dot character
.Rc ( . )
at the beginning of a filename component.
.PP
A tilde
.Rc ( ~ )
as the first character of an argument is used to refer to home directories.
A tilde alone or followed by a slash
.Rc ( / )
is replaced by the value of
.Cr $home ,
which is usually the home directory of the current user.
A tilde followed by a username is replaced with the home directory
of that user, according to
.IR getpwent (3).
.SS "Pattern Matching"
The tilde
.Rc ( ~ )
operator is used in
.I es
for matching strings against wildcard patterns.
The command
.Ds
.Cr "~ \fIsubject\fP \fIpattern\fP \fIpattern\fP ..."
.De
.PP
returns a true value if and only if the subject matches any of the patterns.
The matching follows the same rules as wildcard expansion, except that slashes
.Rc ( / )
are not considered significant, leading dots
.Rc ( . )
do not have to be matched explicitly,
and home directory expansion does not occur.
Thus
.Ds
.Cr "~ foo f*"
.De
.PP
returns zero (true), while
.Ds
.Cr "~ (bar baz) f*"
.De
.PP
returns one (false).
The null list is matched by the null list, so
.Ds
.Cr "~ $foo ()"
.De
.PP
checks to see whether
.Cr $foo
is empty or not.
This may also be achieved
by the test
.Ds
.Cr "~ $#foo 0"
.De
.PP
Note that inside a
.Cr ~
command
.I es
does not match patterns against file
names, so it is not necessary to quote the characters
.Cr "*" ,
.Cr [
and
.Cr "?" .
However,
.I es
does expand the subject against filenames if it contains
metacharacters.
Thus, the command
.Ds
.Cr "~ * ?"
.De
.PP
returns true if any of the files in the current directory have a
single-character name.
Note that if the
.Cr ~
command is given a list as its first
argument, then a successful match against any of the elements of that
list will cause
.Cr ~
to return true.
For example:
.Ds
.Cr "~ (foo goo zoo) z*"
.De
.PP
is true.
.SS "Pattern Extraction"
The double-tilde
.Rc ( ~~ )
operator is used in
.I es
for extracting the parts of strings that match patterns.
The command
.Ds
.Cr "~~ \fIsubject\fP \fIpattern\fP \fIpattern\fP ..."
.De
.PP
returns the parts of each matching subject which correspond to the
wildcards.
.PP
Each subject is checked in order against each pattern; if it matches
the pattern, the parts of the subject which matched each
.Cr "*" ,
.Cr "?" ,
or
.Cr "[]"
character range are extracted, and processing moves on to the next
subject. If the subject does not match, the next pattern is tried.
.PP
For example, the result of the extraction operation
.Ds
.Cr "~~ (foo.c foo.x bar.h) *.[ch]"
.De
.PP
is the list
.Cr "(foo c bar h)" .
.SS "Command Substitution"
A list may be formed from the output of a command by using backquote
substitution:
.Ds
.Ci "\`{" " command " }
.De
.PP
returns a list formed from the standard output of the command in braces.
The characters stored in the variable
.Cr $ifs
(for ``input field separator'')
are used to split the output into list elements.
By default,
.Cr $ifs
has the value space-tab-newline.
The braces may be omitted if the command is a single word.
Thus
.Cr \`ls
may be used instead of
.Cr "\`{ls}" .
This last feature is useful when defining functions that expand
to useful argument lists.
A frequent use is:
.Ds
.Cr "fn src { echo *.[chy] }"
.De
.PP
followed by
.Ds
.Cr "wc \`src"
.De
.PP
(This will print out a word-count of all C and Yacc source files in the current
directory.)
.PP
In order to override the value of
.Cr $ifs
for a single command substitution, use:
.Ds
.Ci "\`\`" " ifs-list " { " command " }
.De
.PP
.Cr $ifs
will be temporarily ignored and the command's output will be split as specified by
the list following the double backquote.
For example:
.Ds
.Cr "\`\` :\en {cat /etc/passwd}"
.De
.PP
splits up
.Cr /etc/passwd
into fields.
.SS "Return Values"
The return value of a command is obtained with the construct
.Ds
.Ci "<={" " command " }
.De
.PP
The return value of an external program is its exit status
(which in other shells can be found in special variables such as
.Cr $?
or
.Cr $status ),
as either a small integer or the name of signal.
Thus
.Ds
.Cr "echo <={test \-f /etc/motd} <={test \-w /vmunix} <=a.out"
.De
.PP
might produce the output
.Ds
.Cr "0 1 sigsegv+core"
.De
.PP
along with any output or error messages from the programs.
.PP
.I Es
functions and primitives can produce ``rich return values,''
that is, arbitrary lists as return values.
.PP
When return values are interpreted as truth values,
an extension of the normal shell conventions apply.
If any element of a list is not equal to
.Rc `` 0 ''
(or the empty string), that list is considered false.
.PP
The return value of an assignment operation is the assigned value.
.SS "Logical Operators"
There are a number of operators in
.I es
which depend on the exit status of a command.
.Ds
.Ic command1 " && " command2
.De
.PP
executes the first command and then executes the second command if and only if
the first command has a ``true'' return value.
.Ds
.Ic command1 " || " command2
.De
.PP
executes the first command and then executes the second command if and only if
the first command has a ``false'' return value.
.Ds
.Ci ! " command"
.De
.PP
inverts the truth value of the exit status of a command.
.SS "Input and output"
.PP
The standard output of a command may be redirected to a file with
.Ds
.Cr "command > file"
.De
.PP
and the standard input may be taken from a file with
.Ds
.Cr "command < file"
.De
.PP
File descriptors other than 0 and 1 may be specified also.
For example, to redirect standard error to a file, use:
.Ds
.Cr "command >[2] file"
.De
.PP
In order to duplicate a file descriptor, use
.Ci >[ n = m ]\fR.
Thus to redirect both standard output and standard error
to the same file, use
.Ds
.Cr "command > file >[2=1]"
.De
.PP
To close a file descriptor that may be open, use
.Ci >[ n =]\fR.
For example, to
close file descriptor 7:
.Ds
.Cr "command >[7=]"
.De
.PP
In order to place the output of a command at the end of an already
existing file, use:
.Ds
.Cr "command >> file"
.De
.PP
If the file does not exist, then it is created.
.PP
To open a file for reading and writing, use the
.Cr <>
redirection operator;
for reading and appending, use
.Cr <>> .
Both of these operators use file descriptor 0 (standard input)
by default.
Similarly,
.Cr ><
truncates a file and opens it for reading and writing, and
.Cr >><
opens a file for reading and appending;
these operators use file descriptor 1 by default.
.PP
``Here documents'' are supported as in
.IR sh (1)
with the use of
.Ds
.Cr "command << 'eof-marker'"
.De
.PP
If the end-of-file marker is quoted,
then no variable substitution occurs inside the here document.
Otherwise, every variable is substituted
by its space-separated-list value (see
.BR "Flat Lists" ,
below),
and if a
.Cr ^
character follows a variable name, it is deleted.
This allows the unambiguous use of variables adjacent to text, as in
.Ds
.Cr $variable^follow
.De
.PP
To include a literal
.Cr $
in a here document created with an unquoted end-of-file marker, use
.Cr $$ .
.PP
Additionally,
.I es
supports ``here strings'', which are like here documents,
except that input is taken directly from a string on the command line.
Its use is illustrated here:
.Ds
.Cr "cat <<< 'this is a here string' | wc"
.De
.PP
(This feature enables
.I es
to export functions that use here documents.)
.SS Pipes
Two or more commands may be combined in a pipeline by placing the
vertical bar
.Rc ( \||\| )
between them.
The standard output (file descriptor 1)
of the command on the left is tied to the standard input (file
descriptor 0) of the command on the right.
The notation
.Ci |[ n = m ]
indicates that file descriptor
.I n
of the left process is connected to
file descriptor
.I m
of the right process.
.Ci |[ n ]
is a shorthand for
.Ci |[ n =0]\fR.
As an example, to pipe the standard error of a command to
.IR wc (1),
use:
.Ds
.Cr "command |[2] wc"
.De
.PP
The exit status of a pipeline is considered true if and only if every
command in the pipeline exits true.
.SS "Input/Output Substitution"
Some commands, like
.IR cmp (1)
or
.IR diff (1),
take their input from named files on the command
line, and do not use standard input.
It is convenient sometimes to build nonlinear
pipelines so that a command like
.I cmp
can read the output of two commands at once.
.I Es
does it like this:
.Ds
.Cr "cmp <{command1} <{command2}"
.De
.PP
compares the output of the two commands.
Note: on some systems, this form of
redirection is implemented with pipes, and since one cannot
.IR lseek (2)
on a pipe, commands that use
.I lseek
will hang.
For example,
most versions of
.I diff
seek on their inputs.
.PP
Data can be sent down a pipe to several commands using
.IR tee (1)
and the output version of this notation:
.Ds
.Cr "echo hi there | tee >{sed 's/^/p1 /'} >{sed 's/^/p2 /'}"
.De
.SS "Program Fragments"
.I Es
allows the intermixing of code with strings.
A program fragment, which is a group of commands enclosed in braces
.Rc ( { " and " } ),
may be used anywhere a word is expected, and is treated as an indivisible unit.
For example, a program fragment may be passed as an argument,
stored in a variable,
or written to a file or pipe.
If a program fragment appears as the first word in a command,
it is executed, and any arguments are ignored.
Thus the following all produce the same output:
.Ds
.Cr "{ echo hello, world }"
.Cr "{ echo hello, world } foo bar"
.Cr "es -c { echo hello, world }"
.Cr "x = { echo hello, world }; $x"
.Cr "echo { echo hello, world } | es"
.Cr "echo { echo hello, world } > foo; es < foo"
.De
.PP
Since program fragments in the first position in a command are executed,
braces may be used as a grouping mechanism for commands.
For example, to run several commands, with output from all of them redirected to
the same file, one can do
.Ds
.Cr "{ date; ps agux; who } > snapshot"
.De
.PP
In addition, program fragments can continue across multiple physical lines
without explicit line continuations, so the above command could also be written:
.Ds
.Cr "{"
.Cr " date"
.Cr " ps agux"
.Cr " who"
.Cr "} > snapshot"
.De
.PP
A
.I lambda
is a variant on a program fragment which takes arguments.
A lambda has the form
.Ds
.Ci @ " parameters " { " commands " }
.De
.PP
The
.I parameters
are one or more variable names, to which arguments of the
lambda are assigned while the
.I commands
are run.
The first argument is assigned to the first variable,
the second to the second, and so on.
If there are more arguments than parameters,
the last named variable is assigned all the remaining arguments;
if there are fewer, the parameters for which there are no arguments
are bound to the empty list.
If no parameters are listed, the variable named
.Cr *
is assigned all the arguments of the lambda.
Note that
.Cr @
is a keyword and not a special character in
.IR es ,
so it must be separated by whitespace from other words.
.PP
As a small example,
.Ds
.Cr "@ { echo $* } hi"
.De
.PP
is a complicated way of producing the output
.Cr hi .
The first word is a function which echoes its
arguments, and the second word is the argument to the function, the word
.Cr hi .
.PP
Lambdas, like other program fragments, can appear anywhere in a list.
A more complicated example in the same spirit:
.Ds
.Cr "@ cmd arg { $cmd $arg } @ { echo $* } hi"
.De
.PP
This command executes a lambda which runs its first argument, named
.Cr cmd ,
using its second argument, named
.Cr arg ,
as the argument for the first.
The first argument of this function is another lambda,
seen previously, and the second argument is the word
.Cr hi .
.PP
These lambda expressions
.Ds
.Cr "@ a b c { echo $c $b $a } 1 2"
.Cr "@ a b c { echo $c $b $a } 1 2 3 4 5"
.De
.PP
produce this output:
.Ds
.Cr "2 1"
.Cr "3 4 5 2 1"
.De
.SS Functions
A function in
.I es
is introduced with the syntax
.Ds
.Ci fn " name parameters " { " commands " } "
.De
.PP
If the function name appears as the first word of a command,
the commands are run, with the named parameters bound to the
arguments to the function.
.PP
The similarity between functions and lambdas is not coincidental.
A function in
.I es
is a variable of the form
.Ci fn\- name\fR.
If name for which the appropriate
.Cr fn-
variable exists is found in the first position of a command,
the value of the variable is substituted for the first word.
The above syntax for creating functions is equivalent to the
variable assignment
.Ds
.Ci fn\- name " = @" " parameters " "{ \fIcommands\fP }"
.De
.PP
Functions may be deleted with the syntax
.Ds
.Ci fn " name"
.De
.PP
which is equivalent to the assignment
.Ds
.Ci fn\- name =
.De
.PP
If, as the most common case, a function variable is bound to a lambda,
when the function is invoked, the variable
.Cr $0
is bound (dynamically, see below) to the name of the function.
.PP
Lambdas are just another form of code fragment, and, as such, can be
exported in the environment, passed as arguments, etc.
The central difference between the two forms is that lambdas bind their arguments,
while simple brace-enclosed groups just ignore theirs.
.SS "Local Variables"
Variable assignments may be made local to a set of commands with the
.Cr local
construct:
.Ds
.Cr "local (\fIvar\fP = \fIvalue\fP; \fIvar\fP = \fIvalue ...\fP) \fIcommand\fP"
.De
.PP
The command may be a program fragment, so for example:
.Ds
.Cr "local (path = /bin /usr/bin; ifs = ) {"
.Cr " " ...
.Cr "}"
.De
.PP
sets
.Cr path
to a minimal useful path and removes
.Cr ifs
for the duration of one long compound command.
.PP
Local-bound variables are exported into the environment,
and will invoke appropriately named settor functions (see below).
.SS "Lexically Scoped Variables"
In addition to local variables,
.I es
supports a different form of temporary variable binding,
using let-bound, or ``lexically scoped,'' variables.
(Lexical scoping is the form of binding used by most compiled
programming languages, such as C or Scheme.)
A lexically scoped variable is introduced with a
.Cr let
statement:
.Ds
.Cr "let (\fIvar\fP = \fIvalue\fP; \fIvar\fP = \fIvalue ...\fP) \fIcommand\fP"
.De
.PP
All references to any of the variables defined in a
.Cr let
statement by any code located lexically (that is, textually) within the
.I command
portion of the statement will refer to the let-bound variable rather than
any environment or local-bound variable;
the immediate text of the
.Cr let
statement is the complete extent of that binding.
That is, lexically bound variables surrounding code fragments
follow those code fragments around.
.PP
An example best shows the difference between
.Cr let
and
.Cr local
(also known as ``dynamic'') binding: (note that
.Rc `` "; " ''
is
.IR es 's
default prompt.)
.Ds
.Cr "; x = foo"
.Cr "; let (x = bar) {"
.Cr " echo $x"
.Cr " fn lexical { echo $x }"
.Cr "}"
.Cr "bar"
.Cr "; local (x = baz) {"
.Cr " echo $x"
.Cr " fn dynamic { echo $x }"
.Cr "}"
.Cr "baz"
.Cr "; lexical"
.Cr "bar"
.Cr "; dynamic"
.Cr "foo"
.Cr "; "
.De
.PP
Lexically bound variables are not exported into the environment,
and never cause the invocation of settor functions.
Function (lambda) parameters are lexically bound to their values.
.SS "For loops"
The command
.Ds
.Cr "for (\fIvar\fP = \fIlist\fP) \fIcommand\fP
.De
.PP
Runs the
.I command
once for each element of the
.IR list ,
with the named variable bound lexically to each
element of the list, in order.
.PP
If multiple bindings are given in the
.Cr for
statement, the looping occurs in parallel and
stops when all lists are exhausted.
When one list is finished before the others,
the corresponding variable is bound to the empty list
for the remaining iterations.
Thus the loop
.Ds
.Cr "for (i = a b c; j = x y) echo $#i $i $#j $j"
.De
.PP
produces the output
.Ds
.Cr "1 a 1 x"
.Cr "1 b 1 y"
.Cr "1 c 0"
.De
.SS "Settor Functions"
A settor function is a variable of the form
.Ci set- var\fR,
which is typically bound to a lambda.
Whenever a value is assigned to the named variable,
the lambda is invoked with its arguments bound to the new value.
While the settor function is running,
the variable
.Cr $0
is bound to the name of the variable being assigned.
The result of the settor function is used as the actual value in
the assignment.
.PP
For example, the following settor function is used to keep
the shell variables
.Cr home
and
.Cr HOME
synchronized.
.Ds
.Cr "set-HOME = @ {"
.Cr " local (set-home = )"
.Cr " home = $*"
.Cr " result $*"
.Cr "}"
.De
.PP
This settor function is called when any assignment is made to the variable
.Cr HOME .
It assigns the new value to the variable
.Cr home ,
but disables any settor function for
.Cr home
to prevent an infinite recursion.
Then it returns its argument unchanged for use in the actual assignment to
.Cr HOME .
.PP
Settor functions do not apply to lexically bound variables.
.SS Primitives
Primitives are internal
.I es
operations that cannot or should not (for reasons of performance) be
written in the interpreter's language.
The set of primitives makes up the run-time library for
.IR es .
.PP
Primitives can be used with the syntax
.Ds
.Ci $& name
.De
.PP
A primitive can be used anywhere a lambda is expected.
The list of primitives is returned as the result of running
the primitive
.Cr $&primitives .
.PP
For details on specific primitives, see the section entitled
.B PRIMITIVES
below.
.SS Exceptions
Exceptions in
.I es
are used for many forms of non-structured control flow,
notably error reporting, signals, and flow of control
constructs such as
.Cr break
and
.Cr return .
.PP
Exceptions are passed up the call chain to catching routines.
A catcher may decide to intercept an exception,
retry the code that caused the exception,
or pass the exception along.
There can only be one exception raised at any time.
.PP
Exceptions are represented by lists.
The first word of an exception is, by convention, the type of exception
being raised.
The following exceptions are known:
.TP
.Cr "break \fIvalue\fP"
Exit from a loop.
The return value of the loop is the argument to the exception.
.TP
.Cr eof
Raised by
.Cr %parse
when the end of input is reached.
.TP
.Cr "error \fIsource message\fP"
A run-time error.
Almost all shell errors are reported with the
.Cr error
exception.
The default interactive loop and the outermost level of the
interpreter catch this exception and print the message.
.I Source
is the name of the routine (typically a primitive) which
raised the error.
.TP
.Cr retry
When raised from a signal catcher,
causes the body of the
.Cr catch
clause to be run again.
.TP
.Cr "return \fIvalue\fP"
Causes the current function to exit, with
.I value
as the return value (exit status).
.TP
.Cr "signal \fIsigname\fP"
Raised when the shell itself receives a signal,
and the signal is listed in the variable
.Cr signals .
.I Signame
is the name of the signal that was raised.
.PP
See the builtin commands
.Cr catch
and
.Cr throw
for details on how to manipulate exceptions.
.SH "SPECIAL VARIABLES"
Several variables are known to
.I es
and are treated specially.
Redefining these variables can change interpreter semantics.
Note that only dynamically bound (top-level or
.Cr local -bound)
variables are interpreted in this way;
the names of lexically bound variables are unimportant.
.TP
.Cr *
The argument list of
.IR es .
.Cr "$1, $2,"
etc. are the same as
.Cr $*(1) ,
.Cr $*(2) ,
etc.
.TP
.Cr $0
Holds the value of
.Cr argv[0]
with which
.I es
was invoked.
Additionally,
.Cr $0
is set to the name of a function for the duration of
the execution of that function, and
.Cr $0
is also set to the name of the
file being interpreted for the duration of a
.Cr "." " command."
.TP
.Cr apid
The process ID of the last process started in the background.
.TP
.Cr history
The name of a file to which commands are appended as
.I es
reads them.
This facilitates the use of a stand-alone history program
(such as
.IR history (1))
which parses the contents of the history file and presents them to
.I es
for reinterpretation.
If
.Cr history
is not set, then
.I es
does not append commands to any file.
.TP
.Cr home
The current user's home directory, used in tilde
.Rc ( ~ )
expansion, as the default directory for the builtin
.Cr cd
command, and as the directory in which
.I es
looks to find its initialization file,
.Cr .esrc ,
if
.I es
has been started up as a login shell.
Like
.Cr path
and
.Cr PATH ,
.Cr home
and
.Cr HOME
are aliased to each other.
.TP
.Cr ifs
The default input field separator, used for splitting up the output of
backquote commands for digestion as a list.
The initial value of
.Cr ifs
is space-tab-newline.
.TP
.Cr noexport
A list of variables which
.I es
will not export.
All variables except for the ones on this list and lexically bound variables
are exported.
.TP
.Cr path
This is a list of directories to search in for commands.
The empty string stands for the current directory.
Note also that an assignment to
.Cr path
causes an automatic assignment to
.Cr PATH ,
and vice-versa.
If neither
.Cr path
nor
.Cr PATH
are set at startup time,
.Cr path
assumes a default value suitable for your system.
This is typically
.Cr "/usr/ucb /usr/bin /bin ''" .
.TP
.Cr pid
The process ID of the currently running
.IR es .
.TP
.Cr prompt
This variable holds the two prompts (in list form) that
.I es
prints.
.Cr $prompt(1)
is printed before each command is read, and
.Cr $prompt(2)
is printed when input is expected to continue on the next
line. (See
.Cr %parse
for details.)
.I es
sets
.Cr $prompt
to
.Cr "('; ' '')"
by default.
The reason for this is that it enables an
.I es
user to grab commands from previous lines using a
mouse, and to present them to
.I es
for re-interpretation; the semicolon
prompt is simply ignored by
.IR es .
The null
.Cr $prompt(2)
also has its
justification: an
.I es
script, when typed interactively, will not leave
.Cr $prompt(2) 's
on the screen,
and can therefore be grabbed by a mouse and placed
directly into a file for use as a shell script, without further editing
being necessary.
.TP
.Cr signals
Contains a list of the signals which
.I es
traps.
Any signal name which is added to this list causes that signal
to raise an
.I es
exception.
For example, to run some commands and make sure some cleanup routine
is called even if the user interrupts or disconnects during the script,
one can use the form:
.Ds
.Cr "local (signals = $signals sighup sigint) {"
.Cr " catch @ e {"
.Cr " cleanup"
.Cr " throw $e"
.Cr " } {"
.Cr " " ...
.Cr " }"
.Cr "}"
.De
.TP
\&
A signal name prefixed by a hyphen
.Rc ( - )
causes that signal to be ignored by
.I es
and all of its child processes, unless one of them resets its handler.
A signal prefixed by a slash
.Rc ( / )
is ignored in the current shell, but retains default behavior in
child processes.
In addition, the signal
.Cr sigint
may be preceeded by the prefix
.Rc ( . )
to indicate that normal shell interrupt processing
(i.e., the printing of an extra newline)
occurs.
By default
.I es
starts up with the values
.Ds
.Cr ".sigint /sigquit /sigterm"
.De
.TP
\&
in
.Cr $signals ;
other values will be on the list if the shell starts up with
some signals ignored.
.PP
The values of
.Cr path
and
.Cr home
are derived from the environment values of
.Cr PATH
and
.Cr HOME
if those values are present.
This is for compatibility with other Unix programs, such as
.IR sh (1).
.Cr $PATH
is assumed to be a colon-separated list.
.SH "SYNTACTIC SUGAR"
.I Es
internally rewrites much of the syntax presented thus far
in terms of calls to shell functions.
Most features of
.I es
that resemble traditional shell features are included in this category.
This rewriting occurs at parse time, as commands are recognized
by the interpreter.
The shell functions that are the results of rewriting are some
of the hook functions documented below.
.PP
The following tables list all of the major rewriting which
.I es
does, with the forms typically entered by the user on the left
and their internal form on the right.
There is no reason for the user to avoid using the right-hand side forms,
except that they are usually less convenient.
To see the internal form of a specific command,
a user can run
.I es
with the
.Cr \-n
and
.Cr \-x
options;
when invoked in this way, the shell prints the internal form of its commands
rather than executing them.
.ta 2.3i
.SS "Control Flow"
.Ds
.ft \*(Cf
! \fIcmd\fP %not {\fIcmd\fP}
\fIcmd\fP & %background {\fIcmd\fP}
\fIcmd1\fP ; \fIcmd2\fP %seq {\fIcmd1\fP} {\fIcmd2\fP}
\fIcmd1\fP && \fIcmd2\fP %and {\fIcmd1\fP} {\fIcmd2\fP}
\fIcmd1\fP || \fIcmd2\fP %or {\fIcmd1\fP} {\fIcmd2\fP}
fn \fIname\fP \fIargs\fP { \fIcmd\fP } fn-^\fIname\fP = @ \fIargs\fP {\fIcmd\fP}
.ft R
.De
.SS "Input/Output Commands"
.Ds
.ft \*(Cf
\fIcmd\fP < \fIfile\fP %open 0 \fIfile\fP {\fIcmd\fP}
\fIcmd\fP > \fIfile\fP %create 1 \fIfile\fP {\fIcmd\fP}
\fIcmd\fP >[\fIn\fP] \fIfile\fP %create \fIn\fP \fIfile\fP {\fIcmd\fP}
\fIcmd\fP >> \fIfile\fP %append 1 \fIfile\fP {\fIcmd\fP}
\fIcmd\fP <> \fIfile\fP %open-write 0 \fIfile\fP {\fIcmd\fP}
\fIcmd\fP <>> \fIfile\fP %open-append 0 \fIfile\fP {\fIcmd\fP}
\fIcmd\fP >< \fIfile\fP %open-create 1 \fIfile\fP {\fIcmd\fP}
\fIcmd\fP >>< \fIfile\fP %open-append 1 \fIfile\fP {\fIcmd\fP}
\fIcmd\fP >[\fIn\fP=] %close \fIn\fP {\fIcmd\fP}
\fIcmd\fP >[\fIm\fP=\fIn\fP] %dup \fIm\fP \fIn\fP {\fIcmd\fP}
\fIcmd\fP << tag \fIinput\fP tag %here 0 \fIinput\fP {\fIcmd\fP}
\fIcmd\fP <<< \fIstring\fP %here 0 \fIstring\fP {\fIcmd\fP}
\fIcmd1\fP | \fIcmd2\fP %pipe {\fIcmd1\fP} 1 0 {\fIcmd2\fP}
\fIcmd1\fP |[\fIm\fP=\fIn\fP] \fIcmd2\fP %pipe {\fIcmd1\fP} \fIm\fP \fIn\fP {\fIcmd2\fP}
\fIcmd1\fP >{ \fIcmd2\fP } %writeto \fIvar\fP {\fIcmd2\fP} {\fIcmd1\fP $\fIvar\fP}
\fIcmd1\fP <{ \fIcmd2\fP } %readfrom \fIvar\fP {\fIcmd2\fP} {\fIcmd1\fP $\fIvar\fP}
.ft R
.De
.SS "Expressions"
.Ds
.ft \*(Cf
$#\fIvar\fP <={%count $\fIvar\fP}
$^\fIvar\fP <={%flatten ' ' $\fIvar\fP}
\`{\fIcmd args\fP} <={%backquote <={%flatten '' $ifs} {\fIcmd args\fP}}
\`\`\fIifs\fP {\fIcmd args\fP} <={%backquote <={%flatten '' \fIifs\fP} {\fIcmd args\fP}}
.ft R
.De
.SH BUILTINS
Builtin commands are shell functions that exist at shell startup time.
Most builtins are indistinguishable from external commands,
except that they run in the context of the shell itself rather than
as a child process.
Many builtins are implemented with primitives (see above).
.PP
Some builtin functions have names that begin with a percent character
.Rc ( % ).
These are commands with some special meaning to the shell,
or are meant for use only by users customizing the shell.
(This distinction is somewhat fuzzy, and the decisions about which functions have
.Cr % -names
are somewhat arbitrary.)
.PP
All builtins can be redefined and extended by the user.
.SS "Builtin Commands"
.TP
.Cr ". \fR[\fP-einvx\fR]\fP \fI file \fR[\fPargs ...\fR]\fP"
Reads
.I file
as input to
.I es
and executes its contents.
The options are a subset of the invocation options for the shell (see below).
.TP
.Cr "access \fR[\fP-n \fIname\fP\fR]\fP \fR[\fP-1e\fR]\fP \fR[\fP-rwx\fR]\fP \fR[\fP-fdcblsp\fR]\fP \fIpath ...\fP"
Tests if the named paths are accessible according to the options presented.
Normally,
.Cr access
returns zero (true) for files which are accessible and a
printable error message (which evaluates as false, according to shell rules)
for files which are not accessible.
If the
.Cr \-1
option is used, the name of the first file which the test succeeds for is returned;
if the test succeeds for no file, the empty list is returned.
However, if the
.Cr \-e
option was used,
.Cr access
raises an
.Cr error
exception.
If the
.Cr \-n
option is used, the pathname arguments are treated as a list of
directories, and the
.I name
option argument is used as a file in those directories
.Rc "(i.e., " \-n
is used for path searching).
.sp 1v
The default test is whether a file exists.
These options change the test:
.IS
.TP
.Cr \-r
Is the file readable (by the current user)?
.TP
.Cr \-w
Is the file writable?
.TP
.Cr \-x
Is the file executable?
.sp .7v
.TP
.Cr \-f
Is the file a plain file?
.TP
.Cr \-d
Is the file a directory?
.TP
.Cr \-c
Is the file a character device?
.TP
.Cr \-b
Is the file a block device?
.TP
.Cr \-l
Is the file a symbolic link?
.TP
.Cr \-s
Is the file a socket?
.TP
.Cr \-p
Is the file a named pipe (FIFO)?
.IE
.TP
.Cr "break \fIvalue\fP"
Exits the current loop.
.I Value
is used as the return value for the loop command.
.TP
.Cr "catch \fIcatcher body\fP"
Runs
.IR body .
If it raises an exception,
.IR catcher
is run and passed the exception as an argument.
.TP
.Cr "cd \fR[\fP\fIdirectory\fP\fR]\fP"
Changes the current directory to
.IR directory .
With no argument,
.Cr cd
changes the current directory to
.Cr "$home" .
.TP
.Cr "echo \fR[\fP-n\fR]\fP \fR[\fP--\fR]\fP \fIargs ...\fP"
Prints its arguments to standard output, terminated by a newline.
Arguments are separated by spaces.
If the first argument is
.Cr "\-n"
no final newline is printed.
If the first argument is
.Cr "\-\|\-" ,
then all other arguments are echoed literally;
this is used for echoing a literal
.Cr "\-n" .
.TP
.Cr "eval \fIlist\fP"
Concatenates the elements of
.I list
with spaces and feeds the resulting string to
the interpreter for rescanning and execution.
.TP
.Cr "exec \fIcmd\fP"
Replaces
.I es
with the given command.
If the
.Cr exec
contains only redirections,
then these redirections apply to the current shell
and the shell does not exit.
For example,
.Ds
.Cr "exec {>[2] err.out}"
.De
.TP
\&
places further output to standard error in the file
.IR err.out .
Unlike some other shells,
.I es
requires that redirections in an
.Cr exec
be enclosed in a program fragment.
.TP
.Cr "exit \fR[\fP\fIstatus\fP\fR]\fP"
Causes the current shell to exit with the given exit
.IR status .
If no argument is given, zero (true) is used.
(This is different from other shells, that often use the status of
the last command executed.)
.TP
.Cr "false"
Always returns a false (non-zero) return value.
.TP
.Cr "forever \fIcmd\fP"
Runs the command repeatedly, until the shell exits or the
command raises an exception.
This is equivalent to a
.Cr "while {true} {\fIcmd\fP}"
loop except that
.Cr forever
does not catch any exceptions, including
.Cr break .
.TP
.Cr "fork \fIcmd\fP"
Runs a command in a subshell.
This insulates the parent shell from the effects
of state changing operations such as
.Cr cd
and variable assignments.
For example:
.Ds
.Cr "fork {cd ..; make}"
.De
.TP
\&
runs
.IR make (1)
in the parent directory
.Rc ( .. ),
but leaves the shell in the current directory.
.TP
.Cr "if \fR[\fP\fItest then\fR]\fP ... \fR[\fPelse\fR]\fP"
Evaluates the command
.IR test .
If the result is true, the command
.I then
is run and
.Cr if
completes.
If the result of the test is false, the next
.I "test-then"
pair is checked, until one where the
.I test
is true is found.
If none of the
.IR test s
are true, the
.I else
command is run.
.TP
.Cr "limit \fR[\fP-h\fR]\fP \fI\fR[\fPresource \fR[\fPvalue\fR]\fP\fR]\fP\fP"
Similar to the
.IR csh (1)
.Cr limit
builtin, this command operates upon the
resource limits of a process.
With no arguments,
.Cr limit
prints all the current limits;
with one argument,
.Cr limit
prints the named limit;
with two arguments, it sets the named limit to the given value.
The
.Cr \-h
flag displays/alters the hard
limits.
The resources which can be shown or altered are
.Cr cputime ,
.Cr filesize ,
.Cr datasize ,
.Cr stacksize ,
.Cr coredumpsize
and
.Cr memoryuse .
For
example:
.Ds
.Cr "limit coredumpsize 0"
.De
.TP
\&
disables core dumps.
.TP
\&
The limit values must either be the word
.Rc `` unlimited ''
or a number with an optional suffix indicating units.
For size limits, the suffixes
.Cr k
(kilobytes),
.Cr m
(megabytes), and
.Cr g
(gigabytes) are recognized.
For time limits,
.Cr s
(seconds),
.Cr m
(minutes), and
.Cr h
(hours) are known;
in addition, times of the form
.Cr "\fIhh\fP:\fImm\fP:\fIss\fP"
and
.Cr "\fImm\fP:\fIss\fP"
are accepted.
See
.IR getrlimit (2)
for details on resource limit semantics.
.TP
.Cr "newpgrp"
Puts
.I es
into a new process group.
This builtin is useful for making
.I es
behave like a job-control shell in a hostile environment.
One example is the NeXT Terminal program, which implicitly assumes
that each shell it forks will put itself into a new process group.
Note that the controlling tty for the process must be on standard error
(file descriptor 2) when this operation is run.
.TP
.Cr "result \fIvalue ...\fP"
Returns its arguments.
This is
.IR es 's
identity function.
.TP
.Cr "return \fIvalue\fP"
Causes the current function to exit,
returning the named
.IR value .
.TP
.Cr "throw \fIexception arg ...\fP"
Raise the named exception, passing all of the arguments to
.Cr throw
to the enclosing exception handler.
.TP
.Cr "time \fIcmd arg ... \fP"
Prints, on the shell's standard error,
the real, user, and system time consumed by
executing the command.
.TP
.Cr "true"
Always returns a true (zero) return value.
.TP
.Cr "umask \fI\fR[\fPmask\fR]"
Sets the current umask (see
.IR umask (2))
to the octal
.IR mask .
If no argument is present, the current mask value is printed.
.TP
.Cr "unwind-protect \fIbody cleanup\fP"
Runs
.I body
and, when it completes or raises an exception, runs
.IR cleanup .
.TP
.Cr "var \fIvar ...\fP"
Prints definitions of the named variables,
suitable for being used as input to the shell.
.TP
.Cr "vars \fR[\fP-vfs\fR]\fP \fR[\fP-epi\fR]\fP"
Prints all shell variables, functions, and settor functions
(in a form suitable for use as shell input),
which match the criteria specified by the options.
.IS
.TP
.Cr \-v
variables (that are not functions or settor functions)
.TP
.Cr \-f
functions
.TP
.Cr \-s
settor functions
.sp .7v
.TP
.Cr \-e
exported values
.TP
.Cr \-p
private (not exported) values
.TP
.Cr \-i
internal (predefined and builtin) values
.sp .7v
.TP
.Cr \-a
all of the above
.IE
.TP
\&
If none of
.Cr \-v ,
.Cr \-f ", or"
.Cr \-s
are specified,
.Cr \-v
is used.
If none of
.Cr \-e ,
.Cr \-p ", or"
.Cr \-i
are specified,
.Cr \-e
is used.
.TP
.Cr "wait \fI\fR[\fPpid\fR]"
Waits for the specified
.IR pid ,
which must have been started by
.IR es .
If no
.I pid
is specified, waits for any child process to exit.
.TP
.Cr "whatis \fIprogam ...\fP"
For each named
.IR program ,
prints the pathname, primitive, lambda, or code fragment which
would be run if the program appeared as the first word of a command.
.TP
.Cr "while \fItest body\fP"
Evaluates the
.I test
and, if it is true, runs the
.I body
and repeats.
.TP
.Cr "%read"
Reads from standard input and returns either the empty list (in the
case of end-of-file) or a single element string with up to one line of
data, including possible redirections. This function reads one
character at a time in order to not read more data out of a pipe than
it should. The terminating newline (if present) is not included in
the returned string.
.SS "Hook Functions"
A subset of the
.Cr % -named
functions are known as ``hook functions.''
The hook functions are called to implement some internal
shell operations, and are available as functions in order
that their values can be changed.
Typically, a call to a hook function is from code generated by
the syntactic sugar rewritings.
.TP
.Cr "%and \fIcmd ...\fP"
Runs the commands in order, stopping after the first one
that has a false return value.
Returns the result of the last command run.
.TP
.Cr "%append \fIfd file cmd\fP"
Runs the command with file descriptor
.I fd
set up to append to the
.IR file .
.TP
.Cr "%background \fIcmd\fP"
Runs the command in the background.
The shell variable
.Cr apid
contains the process ID of the background process,
which is printed if the shell is interactive (according to
.Cr %is-interactive ).
.TP
.Cr "%backquote \fIseparator cmd\fP"
Runs the command in a child process and returns its
standard output as a list, separated (with the same rules used in
.Cr %split )
into elements according to
.IR separator .
.TP
.Cr %batch-loop
Parses commands from the current input source and
passes the commands to the function
.IR %dispatch ,
which is usually a dynamically bound identifier.
This function catches the exception
.Cr eof
which causes it to return.
This function is invoked by the shell on startup and from the dot
.Rc ( . )
and
.Cr eval
commands, when the input source is not interactive.
(See also
.Cr %interactive-loop .)
.TP
.Cr "%close \fIfd cmd\fP"
Runs the command with the given file descriptor closed.
.TP
.Cr "%count \fIlist\fP"
Returns the number of arguments to the primitive.
.TP
.Cr "%create \fIfd file cmd\fP"
Runs the command with file descriptor
.I fd
set up to write to the
.IR file .
.TP
.Cr "%dup \fInewfd oldfd cmd\fP"
Runs the command with the file descriptor
.I oldfd
copied (via
.IR dup (2))
to file descriptor
.IR newfd .
.TP
.Cr "%eval-noprint \fIcmd\fP"
Run the command.
(Passed as the argument to
.Cr %batch-loop
and
.Cr %interactive-loop .)
.TP
.Cr "%eval-print \fIcmd\fP"
Print and run the command.
(Passed as the argument to
.Cr %batch-loop
and
.Cr %interactive-loop
when the
.Cr \-x
option is used.)
.TP
.Cr "%exec-failure \fIfile argv0 args ...\fP"
This function, if it exists, is called in the context of a
child process if an executable file was found but
.IR execve (2)
could not run it.
If the function returns, an error message is printed and the
shell exits, but the function can
.Cr exec
a program if it thinks it knows what to do.
Note that the name of the program appears twice in the
arguments to
.Cr %exec-failure ,
once as a filename and once as the first element of the
.Cr argv
array; in some cases the two will be identical, but in
others the former will be a full pathname and the latter
will just be the basename.
Some versions of
.I es
may provide a builtin version of this function to handle
.Cr #! -style
shell scripts if the kernel does not.
.TP
.Cr "%exit-on-false \fIcmd\fP"
Runs the command, and exits if any command
(except those executing as the tests of conditional statements)
returns a non-zero status.
(This function is used as an argument to
.Cr %batch-loop
and
.Cr %interactive-loop
when the shell is invoked with the
.Cr \-e
option.)
.TP
.Cr "%flatten \fIseparator list\fP"
Concatenate the elements of
.I list
into one string,
separated by the string
.IR separator .
.TP
.Cr "%here \fIfd word ... cmd\fP"
Runs the command with the
.IR word s
passed as input on file descriptor
.IR fd .
.TP
.Cr "%home \fR[\fIuser\fR]"
Returns the home directory of the named user, or
.Cr $home
if there are no arguments.
.TP
.Cr "%interactive-loop"
Prompts,
parses commands from the current input source and
passes the commands to the function
.IR %dispatch ,
which is usually a dynamically bound identifier.
This function catches the exception
.Cr eof
which causes it to return.
This function is invoked by the shell on startup and from the dot
.Rc ( . )
commands, when the input source is interactive.
(See also
.Cr %batch-loop .)
.TP
.Cr "%noeval-noprint \fIcmd\fP"
Do nothing.
(Passed as the argument to
.Cr %batch-loop
and
.Cr %interactive-loop
when the
.Cr \-n
option is used.)
.TP
.Cr "%noeval-print \fIcmd\fP"
Print but don't run the command.
(Passed as the argument to
.Cr %batch-loop
and
.Cr %interactive-loop
when the
.Cr \-x
and
.Cr \-n
options are used.)
.TP
.Cr "%not \fIcmd\fP"
Runs the command and returns false if its exit status was true,
otherwise returns true.
.TP
.Cr "%one \fIlist\fP"
If
.I list
is one element long,
.Cr %one
returns its value;
otherwise it raises an exception.
.Cr %one
is used to ensure that redirection operations get passed exactly one filename.
.TP
.Cr "%open \fIfd file cmd\fP"
Runs the command with
.I file
open for reading on file descriptor
.IR fd .
.TP
.Cr "%open-append \fIfd file cmd\fP"
Runs the command with
.I file
open for reading and appending on file descriptor
.IR fd .
.TP
.Cr "%open-create \fIfd file cmd\fP"
Runs the command with
.I file
open for reading and writing on file descriptor
.IR fd .
If the file already exists, it is truncated.
.TP
.Cr "%open-write \fIfd file cmd\fP"
Runs the command with
.I file
open for reading and writing on file descriptor
.IR fd .
.TP
.Cr "%openfile \fImode fd file cmd\fP"
Runs the command with
.I file
opened according to
.I mode
on file descriptor
.IR fd .
The modes
.Rc ( r ,
.Cr w ,
.Cr a ,
.Cr r+ ,
.Cr w+ ,
and
.Cr a+ )
have the same meanings in
.Cr %openfile
as they do in
.IR fopen (3).
.Cr %openfile
is invoked by the redirection hook functions:
.Cr %append ,
.Cr %create ,
.Cr %open ,
.Cr %open-append ,
.Cr %open-create ,
and
.Cr %open-write .
.TP
.Cr "%or \fIcmd ...\fP"
Runs the commands in order, stopping after the first one
that has a true return value.
Returns the result of the last command run.
.TP
.Cr "%parse \fIprompt1 prompt2\fP"
Reads input from the current input source, printing
.I prompt1
before reading anything and
.I prompt2
before reading continued lines.
Returns a code fragment suitable for execution.
Raises the exception
.Cr eof
on end of input.
.TP
.Cr "%pathsearch \fIprogram\fP"
Looks for an executable file named
.I program
in the directories listed in
.Cr $path .
If such a file is found, it is returned;
if one is not found, an
.Cr error
exception is raised.
.TP
.Cr "%pipe \fIcmd \fP\fR[\fP\fIoutfd infd cmd\fR] ..."
Runs the commands, with the file descriptor
.I outfd
in the left-hand process connected by a pipe to the file descriptor
.I infd
in the right-hand process.
If there are more than two commands,
a multi-stage pipeline is created.
.TP
.Cr "%prompt"
Called by
.Cr %interactive-loop
before every call to
.Cr %parse .
This function allows the user to provide any actions that he or she may
wish to have executed before being prompted (e.g., updating the value of the
.Cr prompt
variable to contain all or part of the current working directory).
.TP
.Cr "%readfrom \fIvar input cmd\fP"
Runs
.I cmd
with the variable
.I var
locally bound
to the name of a file which contains the output of running
the command
.IR input .
.TP
.Cr "%seq \fIcmd ...\fP"
Runs the commands, in order.
.TP
.Cr "%whatis \fIprogram ...\fP"
For each named
.IR program ,
returns the pathname, primitive, lambda, or code fragment which
would be run if the program appeared as the first word of a command.
.TP
.Cr "%writeto \fIvar output cmd\fP"
Runs
.I cmd
with the variable
.I var
locally bound
to the name of a file which is used as the input for the command
.IR output .
.SS "Utility Functions"
These functions are useful for people customizing the shell,
may be used by other builtin commands,
and probably don't make much sense to replace,
though that is always possible.
.TP
.Cr "%apids"
Returns the process IDs of all background processes that the shell
has not yet waited for.
.TP
.Cr "%fsplit \fIseparator \fR[\fIargs ...\fR]"
Splits its arguments into separate strings at every occurrence
of any of the characters in the string
.IR separator .
Repeated instances of separator characters cause null strings to
appear in the result.
(This function is used by some builtin settor functions.)
.TP
.Cr "%is-interactive"
Returns true if the current interpreter context is interactive;
that is, if shell command input is currently coming from an
interactive user.
More precisely, this is true if the innermost enclosing read-eval-print
loop is
.Cr %interactive-loop
rather than
.Cr %batch-loop .
.TP
.Cr "%newfd"
Returns a file descriptor that the shell thinks is not currently in use.
.TP
.Cr "%run \fIprogram argv0 args ...\fP"
Run the named program, which is not searched for in
.Cr $path ,
with the argument vector set to the remaining arguments.
This builtin can be used to set
.Cr argv[0]
(by convention, the name of the program)
to something other than file name.
.TP
.Cr "%split \fIseparator \fR[\fPargs ...\fR]"
Splits its arguments into separate strings at every occurrence
of any of the characters in the string
.IR separator .
Repeated instances of separator characters are coalesced.
Backquote substitution splits with the same rules.
.TP
.Cr "%var \fIvar ...\fP"
For each named variable,
returns a string which, if interpreted by
.I es
would assign to the variable its current value.
.SH PRIMITIVES
Primitives exist in
.I es
so that, in the presence of spoofing and redefinitions,
there is a way to refer to built-in behaviors.
This ability is necessary for the shell to be able to unambiguously refer to itself,
but is also useful for users who have otherwise made their
environment unnecessary but don't want to kill the current shell.
.PP
Primitives are referenced with the
.Ds
.Cr "$&\fIname"
.De
.PP
notation.
In this section, the
.Rc `` $& ''
prefixes will be omitted when primitive names are mentioned.
Note that, by convention, primitive names follow C identifier
names where
.I es
variable and function names often contain
.Rc `` % ''
and
.Rc `` - ''
characters.
.PP
The following primitives directly implement the
builtin functions with the same names:
.ta 1.75i 3.5i
.Ds
.ft \*(Cf
access forever throw
catch fork umask
echo if wait
exec newpgrp
exit result
.ft R
.De
.PP
In addition, the primitive
.Cr dot
implements the
.Rc `` . ''
builtin function.
.PP
The
.Cr cd
primitive is used in the implementation of the
.Cr cd
builtin, but does not understand no arguments to imply
.Cr $home .
The
.Cr vars
and
.Cr internals
primitives are used by the implementation of the
.Cr vars
builtin.
.PP
The following primitives implement the hook functions
of the same names, with
.Rc `` % ''
prefixes:
.ta 1.75i 3.5i
.Ds
.ft \*(Cf
apids here read
close home run
count newfd seq
dup openfile split
flatten parse var
fsplit pipe whatis
.ft R
.De
.PP
The following primitives implement the similar named hook functions,
with
.Rc `` % ''
prefixes and internal hyphens:
.ta 1.75i 3.5i
.Ds
.ft \*(Cf
batchloop exitonfalse isinteractive
.ft R
.De
.PP
The
.Cr background
primitive is used to implement the
.Cr %background
hook function, but does not print the process ID of the
background process or set
.Cr $apid .
The
.Cr backquote
primitive is used to implement the
.Cr %backquote
hook function, but returns the exit status of the child as the
first value of its result instead of setting
.Cr $bqstatus
to it.
.PP
The following primitives implement the similarly named settor functions:
.ta 1.75i 3.5i
.Ds
.ft \*(Cf
sethistory setnoexport setsignals
.ft R
.De
.PP
Some primitives are included in
.I es
conditionally, based on compile-time configuration options.
Those primitives, and the functions to which they are bound, are
.ta 2i
.Ds
.ft \*(Cf
execfailure %exec-failure
limit limit
readfrom %readfrom
time time
writeto %writeto
.ft R
.De
.PP
The primitive
.Cr resetterminal
is if
.I es
is compiled with support for the
.I readline
or
.I editline
libraries.
It is used in the implementation of settor functions of the
.Cr TERM
and
.Cr TERMCAP
variables to notify the line editing packages that the terminal
configuration has changed.
.PP
Several primitives are not directly associated with other function.
They are:
.TP
.Cr "$&collect"
Invokes the garbage collector.
The garbage collector in
.I es
runs rather frequently;
there should be no reason for a user to issue this command.
.TP
.Cr "$&noreturn \fIlambda args ...\fP"
Call the
.IR lambda ,
but in such a way that it does not catch the
.Cr return
exception.
This primitive exists in order that some control-flow
operations in
.I es
(e.g.,
.Cr while
and
.Cr "&&" )
can be implemented as lambdas rather than primitives.
.TP
.Cr "$&primitives"
Returns a list of the names of es primitives.
.TP
.Cr "$&version"
Returns the current version number and release date for
.IR es .
.SH OPTIONS
.TP
.Cr \-c
Run the given
.IR command ,
placing the rest of the arguments to
.I es
in
.Cr $* .
.TP
.Cr \-s
Read commands from standard input;
i.e., put the first argument
to
.I es
in
.Cr $*
rather than using it as the name of a file to source.
.TP
.Cr \-i
Force
.I es
to be an interactive shell.
Normally
.I es
is only interactive if it
is run with commands coming from standard input and
standard input is connected to a terminal.
.TP
.Cr \-l
Run
.Cr $home/.esrc
on startup, i.e., be a login shell.
.Cr \-l
is implied if the name the shell was run under (that is,
.Cr argv[0] )
starts with a dash
.Rc ( - ).
.TP
.Cr \-e
Exit if any command (except those executing as the tests of
conditional statements) returns a non-zero status.
.TP
.Cr \-v
Echo all input to standard error.
.TP
.Cr \-x
Print commands to standard error before executing them.
.TP
.Cr \-n
Turn off execution of commands.
This can be used for checking the syntax of scripts.
When combined with
.Cr \-x ,
.I es
prints the entered command based on the internal (parsed) representation.
.TP
.Cr \-p
Don't initialize functions from the environment.
This is used to help make scripts that don't break unexpectedly when
the environment contains functions that would override commands used in
the script.
.TP
.Cr \-o
Don't open
.Cr /dev/null
on file descriptors 0, 1, and 2, if any of those descriptors are
inherited closed.
.TP
.Cr \-d
Don't trap
.Cr SIGQUIT
or
.Cr SIGTERM .
This is used for debugging.
.SH FILES
.Cr $home/.esrc ,
.Cr /dev/null
.SH BUGS
Lexical scope which is shared by two variables (or closures) in a parent shell
is split in child shells.
.PP
The interpreter should be properly tail recursive;
that is, tail calls should not consume stack space.
.PP
.Cr break
and
.Cr return
should have lexical scope.
.PP
Woe betide the environment string set by some other program to
contain either the character control-a or the sequence control-b
followed by control-a or control-b.
.PP
.Cr \-x
is not nearly as useful as it should be.
.PP
Line numbers in error messages refer to the last line parsed,
rather than something more useful.
.PP
Too many creatures have fept in.
.PP
Please send bug reports to
.Cr "haahr@adobe.com"
and
.Cr "byron@netapp.com" .
.SH "SEE ALSO"
.IR history (1),
.IR rc (1),
.IR sh (1),
.IR execve (2),
.IR getrlimit (2),
.IR fopen (3),
.IR getpwent (3)
.PP
Paul Haahr and Byron Rakitzis,
.I "Es \(em A shell with higher-order functions,"
Proceedings of the Winter 1993 Usenix Conference,
San Diego, CA.
.PP
Tom Duff,
.I "Rc \(em A Shell for Plan 9 and UNIX Systems,"
Unix Research System,
10th Edition,
Volume 2.
(Saunders College Publishing)
|