zsh-users
 help / color / mirror / code / Atom feed
* backslash problems?
@ 1997-10-27 11:31 John Cooper
  1997-10-27 11:53 ` Andrew Main
  1997-10-27 12:36 ` Vincent Lefevre
  0 siblings, 2 replies; 3+ messages in thread
From: John Cooper @ 1997-10-27 11:31 UTC (permalink / raw)
  To: zsh-users; +Cc: john.cooper

[I'm not on the mailing list - please copy me on any replies]

I'm Using zsh 3.0.5-nt-beta-0.28 under NT 4.0.

Can someone explain the following behavior - it seems a little surprising to me.

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


Under bash, it seems more consistent:

$ bash
bash$ echo "foo\bar\baz"
foo\bar\baz
bash$ echo 'foo\bar\baz'
foo\bar\baz
bash$

Thanks,

    --- John


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: backslash problems?
  1997-10-27 11:31 backslash problems? John Cooper
@ 1997-10-27 11:53 ` Andrew Main
  1997-10-27 12:36 ` Vincent Lefevre
  1 sibling, 0 replies; 3+ messages in thread
From: Andrew Main @ 1997-10-27 11:53 UTC (permalink / raw)
  To: john.cooper; +Cc: zsh-users, john.cooper

John Cooper wrote:
>$ echo "foo\bar\baz"
>foaaz

echo gets the argument 'foo\bar\baz', and translates '\b' to backspace.

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

Same.

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

echo gets the argument 'foo\\bar\\baz', and translates '\\' to '\'.

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

This echo desn't translate '\b'.  Use "setopt BSD_ECHO" to get this
behaviour under zsh.

-zefram


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: backslash problems?
  1997-10-27 11:31 backslash problems? John Cooper
  1997-10-27 11:53 ` Andrew Main
@ 1997-10-27 12:36 ` Vincent Lefevre
  1 sibling, 0 replies; 3+ messages in thread
From: Vincent Lefevre @ 1997-10-27 12:36 UTC (permalink / raw)
  To: john.cooper; +Cc: zsh-users

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@ens-lyon.fr> | 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)
-----------------------------------------------------------------------------


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~1997-10-27 12:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-27 11:31 backslash problems? John Cooper
1997-10-27 11:53 ` Andrew Main
1997-10-27 12:36 ` Vincent Lefevre

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).