From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 713 invoked from network); 24 Mar 2005 02:55:35 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 24 Mar 2005 02:55:35 -0000 Received: (qmail 28852 invoked from network); 24 Mar 2005 02:55:29 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 24 Mar 2005 02:55:29 -0000 Received: (qmail 25985 invoked by alias); 24 Mar 2005 02:55:27 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 21062 Received: (qmail 25975 invoked from network); 24 Mar 2005 02:55:26 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 24 Mar 2005 02:55:26 -0000 Received: (qmail 28566 invoked from network); 24 Mar 2005 02:55:26 -0000 Received: from vms042pub.verizon.net (206.46.252.42) by a.mx.sunsite.dk with SMTP; 24 Mar 2005 02:55:22 -0000 Received: from candle.brasslantern.com ([4.11.1.68]) by vms042.mailsrvcs.net (Sun Java System Messaging Server 6.2 HotFix 0.04 (built Dec 24 2004)) with ESMTPA id <0IDU007G55G7X8B1@vms042.mailsrvcs.net> for zsh-workers@sunsite.dk; Wed, 23 Mar 2005 20:55:21 -0600 (CST) Received: from candle.brasslantern.com (IDENT:schaefer@localhost [127.0.0.1]) by candle.brasslantern.com (8.12.11/8.12.11) with ESMTP id j2O2tIjF016004 for ; Wed, 23 Mar 2005 18:55:18 -0800 Received: (from schaefer@localhost) by candle.brasslantern.com (8.12.11/8.12.11/Submit) id j2O2tI5C016003 for zsh-workers@sunsite.dk; Wed, 23 Mar 2005 18:55:18 -0800 Date: Thu, 24 Mar 2005 02:55:17 +0000 From: Bart Schaefer Subject: Re: there should be a way to echo with quotes or escaping In-reply-to: To: zsh-workers@sunsite.dk Message-id: <1050324025517.ZM16002@candle.brasslantern.com> MIME-version: 1.0 X-Mailer: Z-Mail (5.0.0 30July97) Content-type: text/plain; charset=us-ascii References: <87fyylbzte.fsf@ceramic.fifi.org> Comments: In reply to Dave Yost "Re: there should be a way to echo with quotes or escaping" (Mar 23, 6:03pm) X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=-2.6 required=6.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.2 X-Spam-Hits: -2.6 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.