Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: there should be a way to echo with quotes or escaping



At 5:25 PM -0800 2005-03-23, Philippe Troin wrote:
>Dave Yost <Dave@xxxxxxxx> 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



Messages sorted by: Reverse Date, Date, Thread, Author