[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Multi-line bash strings that end in ! improperly treated as event de
Re: Multi-line bash strings that end in ! improperly treated as event designator
Mon, 24 Aug 2015 09:19:53 -0400
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.2.0
On 8/21/15 5:17 PM, Lane Schwartz wrote:
> Bash Version: 4.3
> Patch Level: 11
> Release Status: release
> Per the Bash Reference Manual, section 9.3.1 "Event Designators", a
> bare exclamation point should be treated as "Start[ing] a history
> substitution, except when followed by a space, tab, the end of line, '=',
> or '('". Bash fails to respect this behavior when a multi-line string ends
> in a bare exclamation point. In such cases, the exclamation point is in
> fact followed by the end of line. Despite this fact, Bash treats the
> exclamation point as the start of a history substitution. In contrast, this
> errant behavior is not observed when a bare exclamation point terminates a
> single-line string.
> $ echo "He didn't fall? Inconceivable!"
> $ echo "He didn't fall?
There are a couple of points here. First, the history expansion mechanism
works a line at a time. Second, history expansion does not know much of
anything about shell state or syntax, and is performed very early in the
History expansion knows about vaguely Unix-like quoting with double quotes,
single quotes, and backslashes. It doesn't know about whether or not the
shell is in the middle of reading a multi-line string, and there is no way
to tell it. It can inhibit history expansion within double-quoted strings
when the opening and closing quotes are on the same line (a relatively
recent addition), but not when they appear on different lines.
The last point is that double quote is not listed as one of the characters
that inhibit history expansion in the manual section you quoted. Your
example doesn't show the line ending in a `bare exclamation point'; the
exclamation point is followed by a double quote, not a newline.
This is one place where the intersection of history expansion and shell
syntax is not very clean.
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU address@hidden http://cnswww.cns.cwru.edu/~chet/