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

Re: echo "!" ... what's wrong with the exclamation point ?



Mildred wrote:
> I'm using zsh for some time but I just needed to put an exclamation
> point inside double quotes and I get something wierd:

This is traditional C shell "bang history".  It's described in the
zshexpn manual page under HISTORY EXPANSION.  You can turn it off
with

unsetopt banghistory

if you never use it (it sounds like you don't).  Alternatively,
- single quotes quote the !'s (double quotes don't)
- sticking a !" near the start of the line will turn off bang history
  for that line.
- add an extra \ before an exclamation mark.

Note that !'s are never active in text read from files (including
autoloaded functions), so you only see this effect at the command
line.

> $ echo "abc ! def"
> abc ! def

This still works because a ! followed by a space is specially treated.
That's so other uses of exclamation marks in tests still work.

> $ echo "abc !"
> dquote> "
> abc

This is the use I mentioned above to turn off special handling of !'s
for the rest of the line.  The !" gets swallowed up in one go by
the history mechanism---that's way it's still waiting for a double
quote and you don't get a ! in the output.

> $ echo "abc !! def"
> echo "abc echo "abc
> " def"
> abc echo abc
> zsh: command not found:  def

The !! refers to the complete previous line.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


To access the latest news from CSR copy this link into a web browser:  http://www.csr.com/email_sig.php

To get further information regarding CSR, please visit our Investor Relations page at http://ir.csr.com/csr/about/overview



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