zsh-workers
 help / color / mirror / code / Atom feed
From: Dave Yost <Dave@Yost.com>
To: zsh-workers@sunsite.dk
Subject: Re: there should be a way to echo with quotes or escaping
Date: Wed, 23 Mar 2005 18:03:27 -0800	[thread overview]
Message-ID: <pdy98830621020fbe67cc7ba88c@[192.168.1.2]> (raw)
In-Reply-To: <87fyylbzte.fsf@ceramic.fifi.org>

At 5:25 PM -0800 2005-03-23, Philippe Troin wrote:
>Dave Yost <Dave@Yost.com> writes:
>
>> Z% echo "abc def"
>> abc def
>> Z% echoquoted "abc def"
>> 'abc def'
>> Z% echoescaped "abc def"
>> abc\ def
>> Z%
>>
>> or some such
>>
> > If there is such a feature, I didn't see it mentioned under the echo
>> command in the man page.
>
>% a="foo' bar"
>% echo ${(q)a}
>foo\'\ bar
>% echo ${(qq)a}
>'foo'' bar'
>% echo ${(qqq)a}
>"foo' bar"
>
>Note that I have rc_quotes set, otherwise:
>
>% echo ${(qq)a}
>'foo'\'' bar'
>
>Phil.

This should be documented.  If it's in the man pages somewhere, it's not in a form that one can grep for.  These searches in zshall come up with nothing:
  \${\(q
  qqq
  rc_quotes
and there should be some mention under the echo command.

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.

229 Z% x="a 'b' "'$a `date` "c"'
233 Z%   setopt rc_quotes ; echo ${(q)x} ; echo ${(qq)x} ; echo ${(qqq)x}  
a\ \'b\'\ \$a\ \`date\`\ \"c\"
'a ''b'' $a `date` "c"'
"a 'b' \$a \`date\` \"c\""
234 Z% unsetopt rc_quotes ; echo ${(q)x} ; echo ${(qq)x} ; echo ${(qqq)x}  
a\ \'b\'\ \$a\ \`date\`\ \"c\"
'a '\''b'\'' $a `date` "c"'
"a 'b' \$a \`date\` \"c\""

Perhaps there should be an option (qqqq)? that does something more like what a human would do, like this:

"a 'b' "'$a `date` "c"'

Thanks

Dave


  reply	other threads:[~2005-03-24  2:08 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 [this message]
2005-03-24  2:55     ` Bart Schaefer
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='pdy98830621020fbe67cc7ba88c@[192.168.1.2]' \
    --to=dave@yost.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).