Re: history expansion
"Mark J. Reed" <[email protected]> Thu, 16 Jul 2026 14:47:44 -0400
| Newsgroups | gmane.comp.shells.zsh.user |
|---|---|
| Message-ID | <CAA=-s3zVZiGdjF1Y2j7OMYuTfFwKaXQjr91GgWY4GZPUs9SxtQ@mail.gmail.com> |
--000000000000d08fea0656bee0a0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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=E2=80=AFPM Vincent Lefevre <[email protected]= > wrote: > On 2026-07-14 13:06:17 -0700, Bart Schaefer wrote: > > On Tue, Jul 14, 2026 at 3:42=E2=80=AFAM Vincent Lefevre <vincent@vinc17= .net> > 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=C3=A8vre <[email protected]> - 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) > > --=20 Mark J. Reed <[email protected]> --000000000000d08fea0656bee0a0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Bash tries to be a little cleverer about not invoking hist= ory expansion when it's not intended:<div><br></div><blockquote style= =3D"margin:0 0 0 40px;border:none;padding:0px"><div><font face=3D"monospace= ">bash-5.3$ echo "foo!"</font></div><div><font face=3D"monospace"= >foo!</font></div></blockquote><div><div><br></div><div>But it still does d= o history expansion inside double-quotes:</div><div><br></div></div><blockq= uote style=3D"margin:0 0 0 40px;border:none;padding:0px"><div><div><font fa= ce=3D"monospace">bash-5.3$ echo "foo!!"</font></div></div><div><d= iv><font face=3D"monospace">echo "fooecho "foo!""</font= ></div></div><div><div><font face=3D"monospace">fooecho foo!</font></div></= div></blockquote><div><div><br></div></div><div>So that first command is te= chnically ambiguous; the <b>!"</b>=C2=A0<i>could</i> mean "includ= e the entire previous history line that begins with a double-quote".</= div><div><br></div><blockquote style=3D"margin:0 0 0 40px;border:none;paddi= ng:0px"><div><font face=3D"monospace">bash-5.3$ "ls"</font></div>= <div><font face=3D"monospace">foo</font></div><div><font face=3D"monospace"= >bash-5.3$ !"</font></div><div><font face=3D"monospace">"ls"= </font></div><div><font face=3D"monospace">foo</font></div></blockquote><di= v><br></div><div>Although that doesn't seem to work at all in zsh for s= ome reason:</div><div><br></div><blockquote style=3D"margin:0 0 0 40px;bord= er:none;padding:0px"><div><font face=3D"monospace">zsh% "ls"</fon= t></div><div><font face=3D"monospace">foo</font></div><div><font face=3D"mo= nospace">zsh% !"</font></div><div><font face=3D"monospace">zsh%</font>= </div></blockquote></div><br><div class=3D"gmail_quote gmail_quote_containe= r"><div dir=3D"ltr" class=3D"gmail_attr">On Wed, Jul 15, 2026 at 7:03=E2=80= =AFPM Vincent Lefevre <<a href=3D"mailto:[email protected]">vincent@vin= c17.net</a>> wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"= margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-lef= t:1ex">On 2026-07-14 13:06:17 -0700, Bart Schaefer wrote:<br> > On Tue, Jul 14, 2026 at 3:42=E2=80=AFAM Vincent Lefevre <<a href=3D= "mailto:[email protected]" target=3D"_blank">[email protected]</a>> wr= ote:<br> > > My problem was more with things like<br> > ><br> > >=C2=A0 =C2=A0echo "foo!"<br> > <br> > You probably know this: history expansion takes place inside "...= " but<br> > not inside '...'.<br> <br> Perhaps I should have asked whether anyone relies on history expansion<br> inside double quotes (it is supported by bash, but differently, e.g.<br> no history expansion with the above command in bash).<br> <br> -- <br> Vincent Lef=C3=A8vre <<a href=3D"mailto:[email protected]" target=3D"_b= lank">[email protected]</a>> - Web: <<a href=3D"https://www.vinc17.n= et/" rel=3D"noreferrer" target=3D"_blank">https://www.vinc17.net/</a>><b= r> 100% accessible validated (X)HTML - Blog: <<a href=3D"https://www.vinc17= .net/blog/" rel=3D"noreferrer" target=3D"_blank">https://www.vinc17.net/blo= g/</a>><br> Work: CR INRIA - computer arithmetic / Pascaline project (LIP, ENS-Lyon)<br= > <br> </blockquote></div><div><br clear=3D"all"></div><div><br></div><span class= =3D"gmail_signature_prefix">-- </span><br><div dir=3D"ltr" class=3D"gmail_s= ignature">Mark J. Reed <<a href=3D"mailto:[email protected]" target=3D= "_blank">[email protected]</a>><br></div> --000000000000d08fea0656bee0a0--