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

Re: backslash problems?

On Mon, Oct 27, 1997 at 11:31:05AM +0000, John Cooper wrote:
> $ echo "foo\bar\baz"
> foaaz

Inside double quotes, "b" is already quoted, so "\b" evaluates to \b,
and "foo\bar\baz" evaluates to foo\bar\baz. Then, through zsh's echo,
\b evaluates to backspace (man zshbuiltins) by default. This explains
what is displayed.

> $ echo "foo\\bar\\baz"
> foaaz

Even inside double quotes, "\\" evaluates to a single backslash (this
allows to use \" and \$ inside double quotes). So, "foo\\bar\\baz"
evaluates to foo\bar\baz like in the first case. Therefore you get
the same result as above.

> $ echo 'foo\bar\baz'
> foaaz

Same as in the first case.

> $ echo 'foo\\bar\\baz'
> foo\bar\baz

Inside single quotes, '\\' evaluates to \\. And then, \\ evaluates
to a single backslash.

> Under bash, it seems more consistent:
> $ bash
> bash$ echo "foo\bar\baz"
> foo\bar\baz
> bash$ echo 'foo\bar\baz'
> foo\bar\baz
> bash$

You'll get the same behavior if you use the switch -E with zsh's echo.

man zshbuiltins, command echo gives:

          The -E falg or the BSD_ECHO option can be used to  dis-
          able  these escape sequences. In the later case -e flag
          can be used to enable them.

**** Zsh writers: there's a typo ("falg" instead of "flag").

Vincent Lefevre <vlefevre@xxxxxxxxxxx> | Acorn Risc PC, StrongARM @ 202MHz
WWW: http://www.ens-lyon.fr/~vlefevre/ | 20+1MB RAM, Eagle M2, TV + Teletext
PhD st. in Computer Science, 2nd year  | Apple CD-300, SyQuest 270MB (SCSI)

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