zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@sunsite.dk
Subject: Re: there should be a way to echo with quotes or escaping
Date: Thu, 24 Mar 2005 02:55:17 +0000	[thread overview]
Message-ID: <1050324025517.ZM16002@candle.brasslantern.com> (raw)
In-Reply-To: <pdy98830621020fbe67cc7ba88c@[192.168.1.2]>

On Mar 23,  6:03pm, Dave Yost wrote:
} Subject: Re: there should be a way to echo with quotes or escaping
}
} This should be documented.

It is.  It's under "parameter expansion", along with all the other
expansion flags.

} and there should be some mention under the echo command.

Why?  It has nothing to do with the echo command, or with any other
particular command for that matter.  You can use parameter expansion
anywhere.

} These searches in zshall come up with nothing:
}   \${\(q
}   qqq

The first of those depends on finding a literal example, and the second
assumes that "qqq" would be documented separately from "q" by itself,
which it happens not to be.  Did you happen to think of searching for
the word "quote" all by istelf?

man zshall | grep -i quote

produces 159 lines of output among which is

       q      Quote the resulting words with  backslashes.  If  this  flag  is
              given twice, the resulting words are quoted in single quotes and
              if it is given three times,  the  words  are  quoted  in  double
              quotes.  If it is given four times, the words are quoted in sin-
              gle quotes preceded by a $.

It mentions "quote" so many times, grep extracts the entire paragraph!

}   rc_quotes

This really has nothing to do with it, either, but if you had used
"grep -i" you'd have found it.  (Well, actually, you might not, because
it's rendered in boldface which "man" emits as backspace-overstriking,
so you have to put "man" through something that undoes the overstrike
before you grep it.  If you want a searchable format, don't use "man".)

} Furthermore, none of these three choices is best.  Forgetting the
} rc_quotes option, which is for aliens, they all resort to backslash
} for shell metacharacters like $ ` etc.

"Best" by what definition?

The point is that you specify what outermost quotes you want used, so
that you know what to expect when you embed the expansion another
context.  The problem with "quote like a human" is that zsh can't know
what the surrounding context will be when the expansion finishes, so
it doesn't know how to begin or end.

I wrote some code for zmail, years ago, that attempted to do "quote
like a human" and the border cases (where the string to be quoted itself
ends in a quote, for example) are a disaster.  Most of the time it works
like you seem to think would be "best" but occasionally you get insane
runs of '"'"'" that it's impossible to decipher.  The occasional back-
slash you get with ${(qq)...} really is much preferable.


  reply	other threads:[~2005-03-24  2:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-23 22:00 Dave Yost
2005-03-24  1:25 ` Philippe Troin
2005-03-24  2:03   ` Dave Yost
2005-03-24  2:55     ` Bart Schaefer [this message]
2005-03-24  1:34 ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1050324025517.ZM16002@candle.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).