4

I have zsh 5.3 (through oh-my-zsh), if I run echo --message="foo!", I get unterminated quote prompt on the next line:

$ echo --message="foo!"
dquote>

This doesn' happen in bash.

When I drop the ! character from the argument, it works fine:

$ echo --message="foo"
--message=foo

What’s happening here?


I should also note that if I answer the unterminated quote prompt with " and hit return, I get this output, which totally drops the !:

$ echo --message="foo!"
dquote> "
--message=foo
8

That's the history expansion at work.

This is what the zshexpn(1) manpage says about it:

If the shell encounters the character sequence !" in the input, the history mechanism is temporarily disabled until the current list (see zshmisc(1)) is fully parsed. The !" is removed from the input, and any subsequent ! characters have no special significance.

  • 1
    So as either escape "foo\!" or use single quotes 'foo!'. Or even "foo!"!", !" "foo!", etc.. – Sparhawk Jan 29 at 3:03
  • 1
    What is it expanding? The manpage makes it sound like !" is a special token that disables "the history mechanism", which I assume means it prevents the current line from appearing in the previous command list/history buffer? Wouldn't that be more like 'history compression (or perhaps, excision)'? – aroth Jan 29 at 10:12
  • "history expansion" is the official name of this ! feature -- you call it "csh bangs" if you like. And !" does no more than told in that paragraph; in particular, it does not prevent the current line from being pushed in the history -- why should it? – mosvy Jan 29 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.