Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: history expansion



Bash tries to be a little cleverer about not invoking history expansion when it's not intended:

bash-5.3$ echo "foo!"
foo!

But it still does do history expansion inside double-quotes:

bash-5.3$ echo "foo!!"
echo "fooecho "foo!""
fooecho foo!

So that first command is technically ambiguous; the !" could mean "include the entire previous history line that begins with a double-quote".

bash-5.3$ "ls"
foo
bash-5.3$ !"
"ls"
foo

Although that doesn't seem to work at all in zsh for some reason:

zsh% "ls"
foo
zsh% !"
zsh%

On Wed, Jul 15, 2026 at 7:03 PM Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
On 2026-07-14 13:06:17 -0700, Bart Schaefer wrote:
> On Tue, Jul 14, 2026 at 3:42 AM Vincent Lefevre <vincent@xxxxxxxxxx> wrote:
> > My problem was more with things like
> >
> >   echo "foo!"
>
> You probably know this: history expansion takes place inside "..." but
> not inside '...'.

Perhaps I should have asked whether anyone relies on history expansion
inside double quotes (it is supported by bash, but differently, e.g.
no history expansion with the above command in bash).

--
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Pascaline project (LIP, ENS-Lyon)



--
Mark J. Reed <markjreed@xxxxxxxxx>


Messages sorted by: Reverse Date, Date, Thread, Author