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

Re: ${(q)...} for newline



2010-05-23 21:45:39 +0100, Peter Stephenson:
> Peter Stephenson wrote:
> > Param-style simple (i.e. backslash) quoting of a newline appends a real
> > newline in double quotes.  It seems to me it would occasion far fewer
> > surprises if this never output a literal newline, so this uses $'\n'.
> 
> Also, would I be right in thinking this is an accident waiting to
> happen?
> 
> % foo=(one '' three)
> % print ${(q)foo}
> one three
> 
> Certainly
> 
> % printf "%q\n" ''
> 
> 
> which uses the same quoting internally is incompatible with what bash
> does (it outputs '').  It looks like in both cases (and all explicit
> uses of backslash-quoting --- completion is different) empty strings
> might be better turned into an explicit ''.
[...]

Not in the first case though, as array expansion removes the
empty elements. But in "${(@q)foo}" yes maybe, at least to be
consistent with bash and ksh93 printf %q.

$ zsh -c 'a=(a "" b); printf "<%s>\n" ${(q)a}'
<a>
<b>
$ zsh -c 'a=(a "" b); printf "<%s>\n" "${(q@)a}"'
<a>
<>
<b>

-- 
Stephane



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