Tue Mar 13 21:49:16 2018 UTC ()
Try to improve markup in the Parameter Expansion section.


(uwe)
diff -r1.185 -r1.186 src/bin/sh/sh.1

cvs diff -r1.185 -r1.186 src/bin/sh/sh.1 (expand / switch to unified diff)

--- src/bin/sh/sh.1 2018/03/13 21:04:57 1.185
+++ src/bin/sh/sh.1 2018/03/13 21:49:15 1.186
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1.\" $NetBSD: sh.1,v 1.185 2018/03/13 21:04:57 uwe Exp $ 1.\" $NetBSD: sh.1,v 1.186 2018/03/13 21:49:15 uwe 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
@@ -1605,146 +1605,206 @@ or when in an assignment or not in posix @@ -1605,146 +1605,206 @@ or when in an assignment or not in posix
1605or if neither of those appear, the end of the word, 1605or if neither of those appear, the end of the word,
1606they are treated as a user name 1606they are treated as a user name
1607and are replaced with the pathname of the named user's home directory. 1607and are replaced with the pathname of the named user's home directory.
1608If the user name is missing (as in 1608If the user name is missing (as in
1609.Pa ~/foobar ) , 1609.Pa ~/foobar ) ,
1610the tilde is replaced with the value of the 1610the tilde is replaced with the value of the
1611.Va HOME 1611.Va HOME
1612variable (the current user's home directory). 1612variable (the current user's home directory).
1613.Pp 1613.Pp
1614In variable assignments, 1614In variable assignments,
1615an unquoted tilde immediately after the assignment operator (=), and 1615an unquoted tilde immediately after the assignment operator (=), and
1616each unquoted tilde immediately after an unquoted colon in the value 1616each unquoted tilde immediately after an unquoted colon in the value
1617to be assigned is also subject to tilde expansion as just stated. 1617to be assigned is also subject to tilde expansion as just stated.
 1618.\"
 1619.\"
1618.Ss Parameter Expansion 1620.Ss Parameter Expansion
 1621.\"
1619The format for parameter expansion is as follows: 1622The format for parameter expansion is as follows:
1620.Pp 1623.Pp
1621.Dl ${expression} 1624.Dl ${ Ns Ar expression Ns Li }
1622.Pp 1625.Pp
1623where expression consists of all characters until the matching 1626where
1624.Dq } . 1627.Ar expression
 1628consists of all characters until the matching
 1629.Sq Li } .
1625Any 1630Any
1626.Dq } 1631.Sq Li }
1627escaped by a backslash or within a quoted string, and characters in 1632escaped by a backslash or within a quoted string, and characters in
1628embedded arithmetic expansions, command substitutions, and variable 1633embedded arithmetic expansions, command substitutions, and variable
1629expansions, are not examined in determining the matching 1634expansions, are not examined in determining the matching
1630.Dq } . 1635.Sq Li } .
1631.Pp 1636.Pp
1632The simplest form for parameter expansion is: 1637The simplest form for parameter expansion is:
1633.Pp 1638.Pp
1634.Dl ${parameter} 1639.Dl ${ Ns Ar parameter Ns Li }
1635.Pp 1640.Pp
1636The value, if any, of parameter is substituted. 1641The value, if any, of
 1642.Ar parameter
 1643is substituted.
1637.Pp 1644.Pp
1638The parameter name or symbol can be enclosed in braces, 1645The parameter name or symbol can be enclosed in braces,
1639which are optional in this simple case, 1646which are optional in this simple case,
1640except for positional parameters with more than one digit or 1647except for positional parameters with more than one digit or
1641when parameter is followed by a character that could be interpreted as 1648when parameter is followed by a character that could be interpreted as
1642part of the name. 1649part of the name.
1643If a parameter expansion occurs inside double quotes: 1650If a parameter expansion occurs inside double quotes:
1644.Bl -enum 1651.Bl -enum
1645.It 1652.It
1646Pathname expansion is not performed on the results of the expansion. 1653pathname expansion is not performed on the results of the expansion;
1647.It 1654.It
1648Field splitting is not performed on the results of the 1655field splitting is not performed on the results of the
1649expansion, with the exception of the special rules for @. 1656expansion, with the exception of the special rules for
 1657.Dv @ .
1650.El 1658.El
1651.Pp 1659.Pp
1652In addition, a parameter expansion where braces are used, 1660In addition, a parameter expansion where braces are used,
1653can be modified by using one of the following formats. 1661can be modified by using one of the following formats.
1654If the 1662If the
1655.Dq Dv \&: 1663.Sq Ic \&:
1656is omitted in the following modifiers, then the test in the expansion 1664is omitted in the following modifiers, then the test in the expansion
1657applies only to unset parameters, not null ones. 1665applies only to unset parameters, not null ones.
1658.Bl -tag -width aaparameterwordaaaaa 1666.Bl -tag -width aaparameterwordaaaaa
1659.It ${parameter:\(miword} 1667.It Li ${ Ns Ar parameter Ns Ic :- Ns Ar word Ns Li }
1660Use Default Values. 1668.Sy Use Default Values.
1661If parameter is unset or null, the expansion of word 1669If
1662is substituted; otherwise, the value of parameter is substituted. 1670.Ar parameter
1663.It ${parameter:=word} 1671is unset or null, the expansion of
1664Assign Default Values. 1672.Ar word
1665If parameter is unset or null, the expansion of 1673is substituted; otherwise, the value of
1666word is assigned to parameter. 1674.Ar parameter
1667In all cases, the final value of parameter is substituted. 1675is substituted.
 1676.It Li ${ Ns Ar parameter Ns Ic := Ns Ar word Ns Li }
 1677.Sy Assign Default Values.
 1678If
 1679.Ar parameter
 1680is unset or null, the expansion of
 1681.Ar word
 1682is assigned to
 1683.Ar parameter .
 1684In all cases, the final value of
 1685.Ar parameter
 1686is substituted.
1668Only variables, not positional parameters or special 1687Only variables, not positional parameters or special
1669parameters, can be assigned in this way. 1688parameters, can be assigned in this way.
1670.It ${parameter:?[word]} 1689.It Li ${ Ns Ar parameter Ns Ic :? Ns Oo Ar word\^ Oc Ns Li }
1671Indicate Error if Null or Unset. 1690.Sy Indicate Error if Null or Unset.
1672If parameter is unset or null, the 1691If
1673expansion of word (or a message indicating it is unset if word is omitted) 1692.Ar parameter
 1693is unset or null, the expansion of
 1694.Ar word
 1695(or a message indicating it is unset if
 1696.Ar word
 1697is omitted)
1674is written to standard error and a non-interactive shell exits with 1698is written to standard error and a non-interactive shell exits with
1675a nonzero exit status. 1699a nonzero exit status.
1676An interactive shell will not exit, but any associated command(s) will 1700An interactive shell will not exit, but any associated command(s) will
1677not be executed. 1701not be executed.
1678If the parameter is set, its value is substituted. 1702If the
1679.It ${parameter:+word} 1703.Ar parameter
1680Use Alternative Value. 1704is set, its value is substituted.
1681If parameter is unset or null, null is 1705.It Li ${ Ns Ar parameter Ns Ic :+ Ns Ar word Ns Li }
1682substituted; otherwise, the expansion of word is substituted. 1706.Sy Use Alternative Value.
1683The value of parameter is not used in this expansion. 1707If
1684.It ${#parameter} 1708.Ar parameter
1685String Length. 1709is unset or null, null is substituted;
1686The length in characters of the value of parameter. 1710otherwise, the expansion of
 1711.Ar word
 1712is substituted.
 1713The value of
 1714.Ar parameter
 1715.Em is not used
 1716in this expansion.
 1717.It Li ${ Ns Ic # Ns Ar parameter Ns Li }
 1718.Sy String Length.
 1719The length in characters of the value of
 1720.Ar parameter .
1687.El 1721.El
1688.Pp 1722.Pp
1689The following four varieties of parameter expansion provide for substring 1723The following four varieties of parameter expansion provide for substring
1690processing. 1724processing.
1691In each case, pattern matching notation (see 1725In each case, pattern matching notation (see
1692.Sx Shell Patterns ) , 1726.Sx Shell Patterns ) ,
1693rather than regular expression notation, is used to evaluate the patterns. 1727rather than regular expression notation, is used to evaluate the patterns.
1694If parameter is * or @, the result of the expansion is unspecified. 1728If parameter is
 1729.Dv *
 1730or
 1731.Dv @ ,
 1732the result of the expansion is unspecified.
1695Enclosing the full parameter expansion string in double quotes does not 1733Enclosing the full parameter expansion string in double quotes does not
1696cause the following four varieties of pattern characters to be quoted, 1734cause the following four varieties of pattern characters to be quoted,
1697whereas quoting characters within the braces has this effect. 1735whereas quoting characters within the braces has this effect.
1698.Bl -tag -width aaparameterwordaaaaa 1736.Bl -tag -width aaparameterwordaaaaa
1699.It ${parameter%word} 1737.It Li ${ Ns Ar parameter Ns Ic % Ns Ar word Ns Li }
1700Remove Smallest Suffix Pattern. 1738.Sy Remove Smallest Suffix Pattern.
1701The word is expanded to produce a pattern. 1739The
1702The parameter expansion then results in parameter, with the 1740.Ar word
 1741is expanded to produce a pattern.
 1742The parameter expansion then results in
 1743.Ar parameter ,
 1744with the
1703smallest portion of the suffix matched by the pattern deleted. 1745smallest portion of the suffix matched by the pattern deleted.
1704If the word is to start with a 1746If the
1705.Sq \&% 1747.Ar word
 1748is to start with a
 1749.Sq Li \&%
1706character, it must be quoted. 1750character, it must be quoted.
1707.It ${parameter%%word} 1751.It Li ${ Ns Ar parameter Ns Ic %% Ns Ar word Ns Li }
1708Remove Largest Suffix Pattern. 1752.Sy Remove Largest Suffix Pattern.
1709The word is expanded to produce a pattern. 1753The
1710The parameter expansion then results in parameter, with the largest 1754.Ar word
 1755is expanded to produce a pattern.
 1756The parameter expansion then results in
 1757.Ar parameter ,
 1758with the largest
1711portion of the suffix matched by the pattern deleted. 1759portion of the suffix matched by the pattern deleted.
1712The 1760The
1713.Dq %% 1761.Dq Ic %%
1714pattern operator only produces different results from the 1762pattern operator only produces different results from the
1715.Dq \&% 1763.Dq Ic \&%
1716operator when the pattern contains at least one unquoted 1764operator when the pattern contains at least one unquoted
1717.Sq \&* . 1765.Sq Li \&* .
1718.It ${parameter#word} 1766.It Li ${ Ns Ar parameter Ns Ic \&# Ns Ar word Ns Li }
1719Remove Smallest Prefix Pattern. 1767.Sy Remove Smallest Prefix Pattern.
1720The word is expanded to produce a pattern. 1768The
1721The parameter expansion then results in parameter, with the 1769.Ar word
 1770is expanded to produce a pattern.
 1771The parameter expansion then results in
 1772.Ar parameter ,
 1773with the
1722smallest portion of the prefix matched by the pattern deleted. 1774smallest portion of the prefix matched by the pattern deleted.
1723If the word is to start with a 1775If the
1724.Sq \&# 1776.Ar word
 1777is to start with a
 1778.Sq Li \&#
1725character, it must be quoted. 1779character, it must be quoted.
1726.It ${parameter##word} 1780.It Li ${ Ns Ar parameter Ns Ic \&## Ns Ar word Ns Li }
1727Remove Largest Prefix Pattern. 1781.Sy Remove Largest Prefix Pattern.
1728The word is expanded to produce a pattern. 1782The
1729The parameter expansion then results in parameter, with the largest 1783.Ar word
 1784is expanded to produce a pattern.
 1785The parameter expansion then results in
 1786.Ar parameter ,
 1787with the largest
1730portion of the prefix matched by the pattern deleted. 1788portion of the prefix matched by the pattern deleted.
1731This has the same relationship with the 1789This has the same relationship with the
1732.Sq \&# 1790.Dq Ic \&#
1733pattern operator as 1791pattern operator as
1734.Dq %% 1792.Dq Ic %%
1735has with 1793has with
1736.Dq \&% . 1794.Dq Ic \&% .
1737.El 1795.El
 1796.\"
 1797.\"
1738.Ss Command Substitution 1798.Ss Command Substitution
1739Command substitution allows the output of a command to be substituted in 1799Command substitution allows the output of a command to be substituted in
1740place of the command (and surrounding syntax). 1800place of the command (and surrounding syntax).
1741Command substitution occurs when the command is enclosed as follows: 1801Command substitution occurs when the command is enclosed as follows:
1742.Pp 1802.Pp
1743.Dl $(command) 1803.Dl $(command)
1744.Pp 1804.Pp
1745or 1805or
1746.Po 1806.Po
1747.Dq backquoted 1807.Dq backquoted
1748version 1808version
1749.Pc : 1809.Pc :
1750.Pp 1810.Pp