| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | .\" $NetBSD: sh.1,v 1.194 2018/03/16 11:19:24 kre Exp $ | | 1 | .\" $NetBSD: sh.1,v 1.195 2018/03/16 11:53:57 kre Exp $ |
2 | .\" Copyright (c) 1991, 1993 | | 2 | .\" Copyright (c) 1991, 1993 |
3 | .\" The Regents of the University of California. All rights reserved. | | 3 | .\" The Regents of the University of California. All rights reserved. |
4 | .\" | | 4 | .\" |
5 | .\" This code is derived from software contributed to Berkeley by | | 5 | .\" This code is derived from software contributed to Berkeley by |
6 | .\" Kenneth Almquist. | | 6 | .\" Kenneth Almquist. |
7 | .\" | | 7 | .\" |
8 | .\" Redistribution and use in source and binary forms, with or without | | 8 | .\" Redistribution and use in source and binary forms, with or without |
9 | .\" modification, are permitted provided that the following conditions | | 9 | .\" modification, are permitted provided that the following conditions |
10 | .\" are met: | | 10 | .\" are met: |
11 | .\" 1. Redistributions of source code must retain the above copyright | | 11 | .\" 1. Redistributions of source code must retain the above copyright |
12 | .\" notice, this list of conditions and the following disclaimer. | | 12 | .\" notice, this list of conditions and the following disclaimer. |
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | | 13 | .\" 2. Redistributions in binary form must reproduce the above copyright |
14 | .\" notice, this list of conditions and the following disclaimer in the | | 14 | .\" notice, this list of conditions and the following disclaimer in the |
| @@ -276,27 +276,27 @@ built-in (described later). | | | @@ -276,27 +276,27 @@ built-in (described later). |
276 | Automatically export any variable to which a value is assigned | | 276 | Automatically export any variable to which a value is assigned |
277 | while this flag is set. | | 277 | while this flag is set. |
278 | .It Fl b Em notify | | 278 | .It Fl b Em notify |
279 | Enable asynchronous notification of background job completion. | | 279 | Enable asynchronous notification of background job completion. |
280 | (Not implemented.) | | 280 | (Not implemented.) |
281 | .It Fl C Em noclobber | | 281 | .It Fl C Em noclobber |
282 | Don't overwrite existing files with | | 282 | Don't overwrite existing files with |
283 | .Dq > . | | 283 | .Dq > . |
284 | .It Fl c | | 284 | .It Fl c |
285 | Read commands from the | | 285 | Read commands from the |
286 | .Ar command_string | | 286 | .Ar command_string |
287 | operand instead of, or in addition to, from the standard input. | | 287 | operand instead of, or in addition to, from the standard input. |
288 | Special parameter | | 288 | Special parameter |
289 | .Dv 0 | | 289 | .Dv 0 \" $0 |
290 | will be set from the | | 290 | will be set from the |
291 | .Ar command_name | | 291 | .Ar command_name |
292 | operand if given, and the positional parameters | | 292 | operand if given, and the positional parameters |
293 | .Li ( 1 , 2 , | | 293 | .Li ( 1 , 2 , |
294 | etc.) | | 294 | etc.) |
295 | set from the remaining argument operands, if any. | | 295 | set from the remaining argument operands, if any. |
296 | .Fl c | | 296 | .Fl c |
297 | is only available at invocation, it cannot be | | 297 | is only available at invocation, it cannot be |
298 | .Ic set , | | 298 | .Ic set , |
299 | and there is no form using | | 299 | and there is no form using |
300 | .Dq Cm \&+ . | | 300 | .Dq Cm \&+ . |
301 | .It Fl E Em emacs | | 301 | .It Fl E Em emacs |
302 | Enable the built-in emacs style | | 302 | Enable the built-in emacs style |
| @@ -995,27 +995,27 @@ reached before the delimiter is encounte | | | @@ -995,27 +995,27 @@ reached before the delimiter is encounte |
995 | .\" | | 995 | .\" |
996 | .\" | | 996 | .\" |
997 | .Ss Search and Execution | | 997 | .Ss Search and Execution |
998 | .\" | | 998 | .\" |
999 | There are three types of commands: shell functions, built-in commands, and | | 999 | There are three types of commands: shell functions, built-in commands, and |
1000 | normal programs \(em and the command is searched for (by name) in that order. | | 1000 | normal programs \(em and the command is searched for (by name) in that order. |
1001 | A command that contains a slash | | 1001 | A command that contains a slash |
1002 | .Sq \&/ | | 1002 | .Sq \&/ |
1003 | in its name is always a normal program. | | 1003 | in its name is always a normal program. |
1004 | They each are executed in a different way. | | 1004 | They each are executed in a different way. |
1005 | .Pp | | 1005 | .Pp |
1006 | When a shell function is executed, all of the shell positional parameters | | 1006 | When a shell function is executed, all of the shell positional parameters |
1007 | (note: excluding | | 1007 | (note: excluding |
1008 | .Li 0 , | | 1008 | .Li 0 , \" $0 |
1009 | which is a special, not positional, parameter, and remains unchanged) | | 1009 | which is a special, not positional, parameter, and remains unchanged) |
1010 | are set to the arguments of the shell function. | | 1010 | are set to the arguments of the shell function. |
1011 | The variables which are explicitly placed in the environment of | | 1011 | The variables which are explicitly placed in the environment of |
1012 | the command (by placing assignments to them before the function name) are | | 1012 | the command (by placing assignments to them before the function name) are |
1013 | made local to the function and are set to the values given, | | 1013 | made local to the function and are set to the values given, |
1014 | and exported for the benefit of programs executed with the function. | | 1014 | and exported for the benefit of programs executed with the function. |
1015 | Then the command given in the function definition is executed. | | 1015 | Then the command given in the function definition is executed. |
1016 | The positional parameters, and local variables, are restored to | | 1016 | The positional parameters, and local variables, are restored to |
1017 | their original values when the command completes. | | 1017 | their original values when the command completes. |
1018 | This all occurs within the current shell, and the function | | 1018 | This all occurs within the current shell, and the function |
1019 | can alter variables, or other settings, of the shell, but | | 1019 | can alter variables, or other settings, of the shell, but |
1020 | not the positional parameters nor their related special parameters. | | 1020 | not the positional parameters nor their related special parameters. |
1021 | .Pp | | 1021 | .Pp |
| @@ -1583,58 +1583,58 @@ The | | | @@ -1583,58 +1583,58 @@ The |
1583 | .Ic set | | 1583 | .Ic set |
1584 | built-in can also be used to set or reset them, and | | 1584 | built-in can also be used to set or reset them, and |
1585 | .Ic shift | | 1585 | .Ic shift |
1586 | can be used to manipulate the list. | | 1586 | can be used to manipulate the list. |
1587 | .Pp | | 1587 | .Pp |
1588 | To refer to the 10th (and later) positional parameters, | | 1588 | To refer to the 10th (and later) positional parameters, |
1589 | the form | | 1589 | the form |
1590 | .Li \&${ Ns Ar n Ns Li \&} | | 1590 | .Li \&${ Ns Ar n Ns Li \&} |
1591 | must be used. | | 1591 | must be used. |
1592 | Without the braces, a digit following | | 1592 | Without the braces, a digit following |
1593 | .Dq $ | | 1593 | .Dq $ |
1594 | can only refer to one of the first 9 positional parameters, | | 1594 | can only refer to one of the first 9 positional parameters, |
1595 | or the special parameter | | 1595 | or the special parameter |
1596 | .Dv 0 . | | 1596 | .Dv 0 . \" $0 |
1597 | The word | | 1597 | The word |
1598 | .Dq Li $10 | | 1598 | .Dq Li $10 |
1599 | is treated identically to | | 1599 | is treated identically to |
1600 | .Dq Li ${1}0 . | | 1600 | .Dq Li ${1}0 . |
1601 | .\" | | 1601 | .\" |
1602 | .\" | | 1602 | .\" |
1603 | .Ss Special Parameters | | 1603 | .Ss Special Parameters |
1604 | .\" | | 1604 | .\" |
1605 | A special parameter is a parameter denoted by one of the following special | | 1605 | A special parameter is a parameter denoted by one of the following special |
1606 | characters. | | 1606 | characters. |
1607 | The value of the parameter is listed next to its character. | | 1607 | The value of the parameter is listed next to its character. |
1608 | .Bl -tag -width thinhyphena | | 1608 | .Bl -tag -width thinhyphena |
1609 | .It Dv * | | 1609 | .It Dv * |
1610 | Expands to the positional parameters, starting from one. | | 1610 | Expands to the positional parameters, starting from one. |
1611 | When the | | 1611 | When the |
1612 | expansion occurs within a double-quoted string it expands to a single | | 1612 | expansion occurs within a double-quoted string it expands to a single |
1613 | field with the value of each parameter separated by the first character of | | 1613 | field with the value of each parameter separated by the first character of |
1614 | the | | 1614 | the |
1615 | .Ev IFS | | 1615 | .Ev IFS |
1616 | variable, or by a | | 1616 | variable, or by a |
1617 | .Aq space | | 1617 | .Aq space |
1618 | if | | 1618 | if |
1619 | .Ev IFS | | 1619 | .Ev IFS |
1620 | is unset. | | 1620 | is unset. |
1621 | .It Dv @ | | 1621 | .It Dv @ \" $@ |
1622 | Expands to the positional parameters, starting from one. | | 1622 | Expands to the positional parameters, starting from one. |
1623 | When the expansion occurs within double quotes, each positional | | 1623 | When the expansion occurs within double quotes, each positional |
1624 | parameter expands as a separate argument. | | 1624 | parameter expands as a separate argument. |
1625 | If there are no positional parameters, the | | 1625 | If there are no positional parameters, the |
1626 | expansion of @ generates zero arguments, even when | | 1626 | expansion of @ generates zero arguments, even when |
1627 | .Dv @ | | 1627 | .Dv $@ |
1628 | is double-quoted. | | 1628 | is double-quoted. |
1629 | What this basically means, for example, is | | 1629 | What this basically means, for example, is |
1630 | if | | 1630 | if |
1631 | .Li $1 | | 1631 | .Li $1 |
1632 | is | | 1632 | is |
1633 | .Dq abc | | 1633 | .Dq abc |
1634 | and | | 1634 | and |
1635 | .Li $2 | | 1635 | .Li $2 |
1636 | is | | 1636 | is |
1637 | .Dq def\ ghi , | | 1637 | .Dq def\ ghi , |
1638 | then | | 1638 | then |
1639 | .Li \*q$@\*q | | 1639 | .Li \*q$@\*q |
1640 | expands to | | 1640 | expands to |
| @@ -1657,44 +1657,44 @@ Expands to the process ID of the invoked | | | @@ -1657,44 +1657,44 @@ Expands to the process ID of the invoked |
1657 | A sub-shell retains the same value of | | 1657 | A sub-shell retains the same value of |
1658 | .Dv $ | | 1658 | .Dv $ |
1659 | as its parent. | | 1659 | as its parent. |
1660 | .It Dv \&! | | 1660 | .It Dv \&! |
1661 | Expands to the process ID of the most recent background | | 1661 | Expands to the process ID of the most recent background |
1662 | command executed from the current shell. | | 1662 | command executed from the current shell. |
1663 | For a pipeline, the process ID is that of the last command in the pipeline. | | 1663 | For a pipeline, the process ID is that of the last command in the pipeline. |
1664 | If no background commands have yet been started by the shell, then | | 1664 | If no background commands have yet been started by the shell, then |
1665 | .Dq Dv \&! | | 1665 | .Dq Dv \&! |
1666 | will be unset. | | 1666 | will be unset. |
1667 | Once set, the value of | | 1667 | Once set, the value of |
1668 | .Dq Dv \&! | | 1668 | .Dq Dv \&! |
1669 | will be retained until another background command is started. | | 1669 | will be retained until another background command is started. |
1670 | .It Dv 0 No (zero) | | 1670 | .It Dv 0 No (zero) \" $0 |
1671 | Expands to the name of the shell or shell script. | | 1671 | Expands to the name of the shell or shell script. |
1672 | .El | | 1672 | .El |
1673 | .\" | | 1673 | .\" |
1674 | .\" | | 1674 | .\" |
1675 | .Ss Word Expansions | | 1675 | .Ss Word Expansions |
1676 | .\" | | 1676 | .\" |
1677 | This section describes the various expansions that are performed on words. | | 1677 | This section describes the various expansions that are performed on words. |
1678 | Not all expansions are performed on every word, as explained later. | | 1678 | Not all expansions are performed on every word, as explained later. |
1679 | .Pp | | 1679 | .Pp |
1680 | Tilde expansions, parameter expansions, command substitutions, arithmetic | | 1680 | Tilde expansions, parameter expansions, command substitutions, arithmetic |
1681 | expansions, and quote removals that occur within a single word expand to a | | 1681 | expansions, and quote removals that occur within a single word expand to a |
1682 | single field. | | 1682 | single field. |
1683 | It is only field splitting or pathname expansion that can | | 1683 | It is only field splitting or pathname expansion that can |
1684 | create multiple fields from a single word. | | 1684 | create multiple fields from a single word. |
1685 | The single exception to this | | 1685 | The single exception to this |
1686 | rule is the expansion of the special parameter | | 1686 | rule is the expansion of the special parameter |
1687 | .Dv @ | | 1687 | .Dv @ \" $@ |
1688 | within double quotes, as was described above. | | 1688 | within double quotes, as was described above. |
1689 | .Pp | | 1689 | .Pp |
1690 | The order of word expansion is: | | 1690 | The order of word expansion is: |
1691 | .Bl -enum | | 1691 | .Bl -enum |
1692 | .It | | 1692 | .It |
1693 | Tilde Expansion, Parameter Expansion, Command Substitution, | | 1693 | Tilde Expansion, Parameter Expansion, Command Substitution, |
1694 | Arithmetic Expansion (these all occur at the same time). | | 1694 | Arithmetic Expansion (these all occur at the same time). |
1695 | .It | | 1695 | .It |
1696 | Field Splitting is performed on fields | | 1696 | Field Splitting is performed on fields |
1697 | generated by step (1) unless the | | 1697 | generated by step (1) unless the |
1698 | .Ev IFS | | 1698 | .Ev IFS |
1699 | variable is null. | | 1699 | variable is null. |
1700 | .It | | 1700 | .It |
| @@ -1755,27 +1755,27 @@ is substituted. | | | @@ -1755,27 +1755,27 @@ is substituted. |
1755 | .Pp | | 1755 | .Pp |
1756 | The parameter name or symbol can be enclosed in braces, | | 1756 | The parameter name or symbol can be enclosed in braces, |
1757 | which are optional in this simple case, | | 1757 | which are optional in this simple case, |
1758 | except for positional parameters with more than one digit or | | 1758 | except for positional parameters with more than one digit or |
1759 | when parameter is followed by a character that could be interpreted as | | 1759 | when parameter is followed by a character that could be interpreted as |
1760 | part of the name. | | 1760 | part of the name. |
1761 | If a parameter expansion occurs inside double quotes: | | 1761 | If a parameter expansion occurs inside double quotes: |
1762 | .Bl -enum | | 1762 | .Bl -enum |
1763 | .It | | 1763 | .It |
1764 | pathname expansion is not performed on the results of the expansion; | | 1764 | pathname expansion is not performed on the results of the expansion; |
1765 | .It | | 1765 | .It |
1766 | field splitting is not performed on the results of the | | 1766 | field splitting is not performed on the results of the |
1767 | expansion, with the exception of the special rules for | | 1767 | expansion, with the exception of the special rules for |
1768 | .Dv @ . | | 1768 | .Dv @ . \" $@ |
1769 | .El | | 1769 | .El |
1770 | .Pp | | 1770 | .Pp |
1771 | In addition, a parameter expansion where braces are used, | | 1771 | In addition, a parameter expansion where braces are used, |
1772 | can be modified by using one of the following formats. | | 1772 | can be modified by using one of the following formats. |
1773 | If the | | 1773 | If the |
1774 | .Sq Ic \&: | | 1774 | .Sq Ic \&: |
1775 | is omitted in the following modifiers, then the test in the expansion | | 1775 | is omitted in the following modifiers, then the test in the expansion |
1776 | applies only to unset parameters, not null ones. | | 1776 | applies only to unset parameters, not null ones. |
1777 | .Bl -tag -width aaparameterwordaaaaa | | 1777 | .Bl -tag -width aaparameterwordaaaaa |
1778 | .It Li ${ Ns Ar parameter Ns Ic :- Ns Ar word Ns Li } | | 1778 | .It Li ${ Ns Ar parameter Ns Ic :- Ns Ar word Ns Li } |
1779 | .Sy Use Default Values. | | 1779 | .Sy Use Default Values. |
1780 | If | | 1780 | If |
1781 | .Ar parameter | | 1781 | .Ar parameter |
| @@ -1829,27 +1829,27 @@ in this expansion. | | | @@ -1829,27 +1829,27 @@ in this expansion. |
1829 | .Sy String Length. | | 1829 | .Sy String Length. |
1830 | The length in characters of the value of | | 1830 | The length in characters of the value of |
1831 | .Ar parameter . | | 1831 | .Ar parameter . |
1832 | .El | | 1832 | .El |
1833 | .Pp | | 1833 | .Pp |
1834 | The following four varieties of parameter expansion provide for substring | | 1834 | The following four varieties of parameter expansion provide for substring |
1835 | processing. | | 1835 | processing. |
1836 | In each case, pattern matching notation (see | | 1836 | In each case, pattern matching notation (see |
1837 | .Sx Shell Patterns ) , | | 1837 | .Sx Shell Patterns ) , |
1838 | rather than regular expression notation, is used to evaluate the patterns. | | 1838 | rather than regular expression notation, is used to evaluate the patterns. |
1839 | If parameter is | | 1839 | If parameter is |
1840 | .Dv * | | 1840 | .Dv * |
1841 | or | | 1841 | or |
1842 | .Dv @ , | | 1842 | .Dv @ , \" $@ |
1843 | the result of the expansion is unspecified. | | 1843 | the result of the expansion is unspecified. |
1844 | Enclosing the full parameter expansion string in double quotes does not | | 1844 | Enclosing the full parameter expansion string in double quotes does not |
1845 | cause the following four varieties of pattern characters to be quoted, | | 1845 | cause the following four varieties of pattern characters to be quoted, |
1846 | whereas quoting characters within the braces has this effect. | | 1846 | whereas quoting characters within the braces has this effect. |
1847 | .Bl -tag -width aaparameterwordaaaaa | | 1847 | .Bl -tag -width aaparameterwordaaaaa |
1848 | .It Li ${ Ns Ar parameter Ns Ic % Ns Ar word Ns Li } | | 1848 | .It Li ${ Ns Ar parameter Ns Ic % Ns Ar word Ns Li } |
1849 | .Sy Remove Smallest Suffix Pattern. | | 1849 | .Sy Remove Smallest Suffix Pattern. |
1850 | The | | 1850 | The |
1851 | .Ar word | | 1851 | .Ar word |
1852 | is expanded to produce a pattern. | | 1852 | is expanded to produce a pattern. |
1853 | The parameter expansion then results in | | 1853 | The parameter expansion then results in |
1854 | .Ar parameter , | | 1854 | .Ar parameter , |
1855 | with the | | 1855 | with the |
| @@ -2867,35 +2867,35 @@ not to the global variable named | | | @@ -2867,35 +2867,35 @@ not to the global variable named |
2867 | Another way to view this, is as if the shell just has one flat, global, | | 2867 | Another way to view this, is as if the shell just has one flat, global, |
2868 | namespace, in which all variables exist. | | 2868 | namespace, in which all variables exist. |
2869 | The | | 2869 | The |
2870 | .Ic local | | 2870 | .Ic local |
2871 | command conceptually copies the variable(s) named to unnamed temporary | | 2871 | command conceptually copies the variable(s) named to unnamed temporary |
2872 | variables, and when the function ends, copies them back again. | | 2872 | variables, and when the function ends, copies them back again. |
2873 | All references to the variables reference the same global variables, | | 2873 | All references to the variables reference the same global variables, |
2874 | but while the function is active, after the | | 2874 | but while the function is active, after the |
2875 | .Ic local | | 2875 | .Ic local |
2876 | command has run, the values and attributes of the variables might | | 2876 | command has run, the values and attributes of the variables might |
2877 | be altered, and later, when the function completes, be restored. | | 2877 | be altered, and later, when the function completes, be restored. |
2878 | .Pp | | 2878 | .Pp |
2879 | Note that the positional parameters | | 2879 | Note that the positional parameters |
2880 | .Li 1 , | | 2880 | .Li 1 , \" $1 |
2881 | .Li 2 , | | 2881 | .Li 2 , \" $2 |
2882 | \&... (see | | 2882 | \&... (see |
2883 | .Sx Positional Parameters ) , | | 2883 | .Sx Positional Parameters ) , |
2884 | and the special parameters | | 2884 | and the special parameters |
2885 | .Li \&# , | | 2885 | .Li \&# , \" $# |
2886 | .Li \&* | | 2886 | .Li \&* \" $* |
2887 | and | | 2887 | and |
2888 | .Li \&@ | | 2888 | .Li \&@ \" $@ |
2889 | (see | | 2889 | (see |
2890 | .Sx Special Parameters ) , | | 2890 | .Sx Special Parameters ) , |
2891 | are always made local in all functions, and are reset inside the | | 2891 | are always made local in all functions, and are reset inside the |
2892 | function to represent the options and arguments passed to the function. | | 2892 | function to represent the options and arguments passed to the function. |
2893 | Note that | | 2893 | Note that |
2894 | .Li $0 | | 2894 | .Li $0 |
2895 | however retains the value it had outside the function, | | 2895 | however retains the value it had outside the function, |
2896 | as do all the other special parameters. | | 2896 | as do all the other special parameters. |
2897 | .Pp | | 2897 | .Pp |
2898 | The only special parameter that can optionally be made local is | | 2898 | The only special parameter that can optionally be made local is |
2899 | .Dq Li \- . | | 2899 | .Dq Li \- . |
2900 | Making | | 2900 | Making |
2901 | .Dq Li \- | | 2901 | .Dq Li \- |
| @@ -3162,27 +3162,27 @@ has no parameters, and exits with an exi | | | @@ -3162,27 +3162,27 @@ has no parameters, and exits with an exi |
3162 | an attempt is made to give it an option. | | 3162 | an attempt is made to give it an option. |
3163 | .It Ic trap Ar action signal ... | | 3163 | .It Ic trap Ar action signal ... |
3164 | .It Ic trap \- | | 3164 | .It Ic trap \- |
3165 | .It Ic trap Op Fl l | | 3165 | .It Ic trap Op Fl l |
3166 | .It Ic trap Oo Fl p Oc Ar signal ... | | 3166 | .It Ic trap Oo Fl p Oc Ar signal ... |
3167 | .It Ic trap Ar N signal ... | | 3167 | .It Ic trap Ar N signal ... |
3168 | .Pp | | 3168 | .Pp |
3169 | Cause the shell to parse and execute action when any of the specified | | 3169 | Cause the shell to parse and execute action when any of the specified |
3170 | signals are received. | | 3170 | signals are received. |
3171 | The signals are specified by signal number or as the name of the signal. | | 3171 | The signals are specified by signal number or as the name of the signal. |
3172 | If | | 3172 | If |
3173 | .Ar signal | | 3173 | .Ar signal |
3174 | is | | 3174 | is |
3175 | .Li 0 | | 3175 | .Li 0 \" $0 |
3176 | or its equivalent, | | 3176 | or its equivalent, |
3177 | .Li EXIT , | | 3177 | .Li EXIT , |
3178 | the action is executed when the shell exits. | | 3178 | the action is executed when the shell exits. |
3179 | The | | 3179 | The |
3180 | .Ar action | | 3180 | .Ar action |
3181 | may be a null (empty) string, | | 3181 | may be a null (empty) string, |
3182 | which causes the specified signals to be ignored. | | 3182 | which causes the specified signals to be ignored. |
3183 | With | | 3183 | With |
3184 | .Ar action | | 3184 | .Ar action |
3185 | set to | | 3185 | set to |
3186 | .Sq Li - | | 3186 | .Sq Li - |
3187 | the specified signals are set to their default actions. | | 3187 | the specified signals are set to their default actions. |
3188 | If the first | | 3188 | If the first |