Date: Thu, 16 Mar 2017 23:06:14 -0400 From: Wayne Pollock <profwaynepoll...@gmail.com> Message-ID: <b5b540ef-3de8-474d-ba4c-bfd093170...@gmail.com>
| echo "\$ foo" | produce: | $ foo Yes. | \$ foo No. | The <backslash> shall retain its special meaning as | an escape character (see Escape Character (Backslash)) | only when followed by one of the following characters | when considered special: "considered special" is a magic term, not just "happens to expand to something" - whether a character is special or not depends upon the context in which the examination is made, and not at all on what happens to be in the string. That "$ " expands to "$ " rather than something else is immaterial, the '\' causes the '$' to be just a boring non-entity characted, so that the character that follows it is not examined for a $ expansion at all. It happens (and must happen) in that order, we cannot look at what comes after the '$' to see if the '$' is an expanding $ or not. For example the text inside $(( )) is treated as a double quoted string, except that the " character is not "considered special" in that string. That means that \" is not needed to embed a literal " in that kind of string (not that doing so would be useful). A similar thing applies in the case of here documents (with unquoted <<term so expansions happen - a case in which " characters are much more likely to occur. '$' characters, and ` (etc) are "considered special" in both those cases.) | A related question is what happens if a dollar-sign is | the last character But yes, that one is a good point, "end of input" should be treated the same as space, newline, etc. At the minute what happens to a '$' that is not followed by anything is unspecified (in the literal sense - the text only talks about what happens when the 'following char' is ... and says nothing at all about what happens when there is no following char.) That should be fixed, so this (new) wording ... If a '$' that is neither within single-quotes nor escaped by a <backslash> is immediately followed by a character that is not a <space>, not a <tab>, not a <newline>, and is not one of the following: [...] the result is unspecified. If a '$' that is neither within single-quotes nor escaped by a <backslash> is immediately followed by a <space>, <tab>, or a <newline>, the '$' shall be treated as a literal character. should instead be ... If a '$' that is neither within single-quotes nor escaped by a <backslash> is immediately followed by a character that is not a <space>, not a <tab>, not a <newline>, and is not one of the following: [...] the result is unspecified. If a '$' that is neither within single-quotes nor escaped by a <backslash> is immediately followed by a <space>, <tab>, or a <newline>, or is not followed by any character, the '$' shall be treated as a literal character. kre