[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: ! history expansion occurs within arithmetic substitutions
From: |
Dale R. Worley |
Subject: |
Re: ! history expansion occurs within arithmetic substitutions |
Date: |
Fri, 11 Aug 2023 12:29:15 -0400 |
Andreas Schwab <schwab@linux-m68k.org> writes:
>> More troublesome, I think, are several variable substitutions which
>> include "!" followed by a name. But I doubt they're used much in
>> interactive mode.
>
> The history expansion is smart enough to not interfere with ${!var}.
Yes... Also, the same magic seems to apply to $!, even if it isn't at
the end of a word. The manual page should probably mention the criteria
for suppressing history expansion there, whatever they are. Perhaps
"history expansion is not triggered by the history expansion character
when it is part of a variable reference" is unambiguous enough;
quoting (anti-recognition) of ! and $ have the same rules, I think.
I was checking the manual page again, and I think it would be clearer
(certainly, would be to me) if a paragraph break was inserted as
follows:
History expansion is performed immediately after a complete line is
read, before the shell breaks it into words, and is performed on each
line individually without taking quoting on previous lines into acâ
count. It takes place in two parts. The first is to determine which
line from the history list to use during substitution. The second is
to select portions of that line for inclusion into the current one.
The line selected from the history is the event, and the portions of
that line that are acted upon are words. Various modifiers are availâ
able to manipulate the selected words.
The line is broken into words
in the same fashion as when reading input, so that several metacharacâ
ter-separated words surrounded by quotes are considered one word. Hisâ
tory expansions are introduced by the appearance of the history expanâ
sion character, which is ! by default. Only backslash (\) and single
quotes can quote the history expansion character, but the history exâ
pansion character is also treated as quoted if it immediately precedes
the closing double quote in a double-quoted string.
The first part talks mostly about what history substitutions *do* and
the second talks about how they are triggered, which isn't a
continuation of the first part. Indeed, I think that it would be
clearer to rearrange them into:
History expansion is performed immediately after a complete line
is read, before the shell breaks it into words, and is performed
on each line individually without taking quoting on previous
lines into account. The line is broken into words in the same
fashion as when reading input, so that several
metacharacter-separated words surrounded by quotes are considered
one word. History expansions are introduced by the appearance of
the history expansion character, which is ! by default. Only
backslash (\) and single quotes can quote the history expansion
character, but the history expansion character is also treated as
quoted if it immediately precedes the closing double quote in a
double-quoted string.
History expansion takes place in two parts. The first is to
determine which line from the history list to use during
substitution. The second is to select portions of that line for
inclusion into the current one. The line selected from the
history is the event, and the portions of that line that are
acted upon are words (as determined above). Various modifiers
are available to manipulate the selected words.
Dale
Re: !; is interpreted as an history expansion that can never match anything, Dale R. Worley, 2023/08/08
Re: !; is interpreted as an history expansion that can never match anything, Chet Ramey, 2023/08/08