zsh-users
 help / color / mirror / code / Atom feed
* Printing square brackets and backslashes
@ 2005-10-23 21:43 DervishD
  2005-10-24  0:04 ` DervishD
  0 siblings, 1 reply; 4+ messages in thread
From: DervishD @ 2005-10-23 21:43 UTC (permalink / raw)
  To: Zsh Users

    Hi all :)

    $ print \[\\\]
    []
    $ /bin/echo -e \[\\\]
    [\]
    $ print -r \[\\\]
    [\]
    $ print \\
    \

    I was expecting the second when issuing the first command...
As I understand, the string should be interpreted as "a quoted
opening square bracket, a quoted backslash, a quoted closing square
bracket", but it is not :?? But in the last case, "print" is
correctly quoting the backslash :?

    I discovered this when I accidentally created a file named "[\]"
when testing the behaviour that one of my scripts has with weird
characters, and then I did "print *" and got that problem.

    What am I misunderstanding here? Thanks a lot in advance :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...


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

* Re: Printing square brackets and backslashes
  2005-10-23 21:43 Printing square brackets and backslashes DervishD
@ 2005-10-24  0:04 ` DervishD
  2005-10-24  0:30   ` Chris Johnson
  0 siblings, 1 reply; 4+ messages in thread
From: DervishD @ 2005-10-24  0:04 UTC (permalink / raw)
  To: Zsh Users

    Hi all :)

    Just a note:

 * DervishD <zsh@dervishd.net> dixit:
>     Hi all :)
> 
>     $ print \[\\\]
>     []
>     $ /bin/echo -e \[\\\]
>     [\]
>     $ print -r \[\\\]
>     [\]
>     $ print \\
>     \

    I can understand the first case, but I don't understand the last
one: in the first case, what I misunderstood is that the shell quotes
the chars, producing "[\]" and "print" prints them, interpreting some
escape directives: "[]". But in the last case, nothing should then be
printed, because zsh quotes the backslash and "print" gets a single
backslash, that is, an empty escape directive that shouldn't print
anything :? Is "print" assuming that a single backslash is not an
empty escape directive? Is a single, isolated backslash a synonim for
"\\"?

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...


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

* Re: Printing square brackets and backslashes
  2005-10-24  0:04 ` DervishD
@ 2005-10-24  0:30   ` Chris Johnson
  2005-10-24  8:16     ` DervishD
  0 siblings, 1 reply; 4+ messages in thread
From: Chris Johnson @ 2005-10-24  0:30 UTC (permalink / raw)
  To: DervishD, Zsh Users

DervishD sent me the following 0.9K:

> >     Hi all :)
> > 
> >     $ print \[\\\]
> >     []
> >     $ /bin/echo -e \[\\\]
> >     [\]
> >     $ print -r \[\\\]
> >     [\]
> >     $ print \\
> >     \
> 
>     I can understand the first case, but I don't understand the last
> one: in the first case, what I misunderstood is that the shell quotes
> the chars, producing "[\]" and "print" prints them, interpreting some
> escape directives: "[]". But in the last case, nothing should then be
> printed, because zsh quotes the backslash and "print" gets a single
> backslash, that is, an empty escape directive that shouldn't print
> anything :? Is "print" assuming that a single backslash is not an
> empty escape directive? Is a single, isolated backslash a synonim for
> "\\"?

This is in the zsh user's guide at:

   http://zsh.sourceforge.net/Guide/zshguide03.html#l32

Look under section 3.2.1, Builtins for printing.

# -------------------------------------------------------------------- 

Secondly, those backslashes can land you in real quoting difficulties.
Normally a backslash on the command line escapes the next character ---
this is a different form of escaping to print's --- so

  print \n

doesn't produce a newline, it just prints out an `n'. So you need to
quote that. This means

  print \\

passes a single backslash to quote, and

  print \\n

or

  print '\n'

prints a newline (followed by the extra one that's usually there). To
print a real backslash, you would thus need

  print \\\\

Actually, you can get away with the two if there's nothing else after
--- print just shrugs its shoulders and outputs what it's been given ---
but that's not a good habit to get into.

-- 
Chris Johnson
cjohnson@cs.utk.edu
http://www.cs.utk.edu/~cjohnson


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

* Re: Printing square brackets and backslashes
  2005-10-24  0:30   ` Chris Johnson
@ 2005-10-24  8:16     ` DervishD
  0 siblings, 0 replies; 4+ messages in thread
From: DervishD @ 2005-10-24  8:16 UTC (permalink / raw)
  To: Chris Johnson; +Cc: Zsh Users

    Hi Chris :)

 * Chris Johnson <cjohnson@cs.utk.edu> dixit:
> DervishD sent me the following 0.9K:
> 
> > >     Hi all :)
> > > 
> > >     $ print \[\\\]
> > >     []
> > >     $ /bin/echo -e \[\\\]
> > >     [\]
> > >     $ print -r \[\\\]
> > >     [\]
> > >     $ print \\
> > >     \
> > 
> >     I can understand the first case, but I don't understand the last
> > one: in the first case, what I misunderstood is that the shell quotes
> > the chars, producing "[\]" and "print" prints them, interpreting some
> > escape directives: "[]". But in the last case, nothing should then be
> > printed, because zsh quotes the backslash and "print" gets a single
> > backslash, that is, an empty escape directive that shouldn't print
> > anything :? Is "print" assuming that a single backslash is not an
> > empty escape directive? Is a single, isolated backslash a synonim for
> > "\\"?
> 
> This is in the zsh user's guide at:
> 
>    http://zsh.sourceforge.net/Guide/zshguide03.html#l32
> 
> Look under section 3.2.1, Builtins for printing.

    Thanks!. I read the Guide a time ago and obviously I missed this.
Thanks again, Chris, it has been very useful :)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...


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

end of thread, other threads:[~2005-10-24  8:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-23 21:43 Printing square brackets and backslashes DervishD
2005-10-24  0:04 ` DervishD
2005-10-24  0:30   ` Chris Johnson
2005-10-24  8:16     ` DervishD

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).