Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Printing arrays for use with $()
- X-seq: zsh-users 9297
- From: Dan Nelson <dnelson@xxxxxxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxxxxx>
- Subject: Re: Printing arrays for use with $()
- Date: Thu, 11 Aug 2005 14:40:46 -0500
- In-reply-to: <20050811161654.GA8200@DervishD>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20050811161654.GA8200@DervishD>
In the last episode (Aug 11), DervishD said:
> I have a script which produces a list of files to stdout. It just
> prints an array (namely, something like "print -l -- $array" right
> now), and I want to use that list in this way:
>
> whatevercommand $(myscript)
>
> Obviously the above doesn't work because the spaces in the file
> names are not quoted (special character like the square brackets are,
> though), but I cannot do this:
>
> print -l -- ${(qq)array}
>
> for printing because then even the single quotes are quoted (this
> happens too using three and four 'q' flags).
Why not use ${(q)array}? You probably also want to use print -r,
othersize it will try and parse \-escape codes.
dan% a=("file name" single\'quote double\"quote)
dan% echo ${(q)a}
file\ name single\'quote double\"quote
dan% echo ${(qq)a}
'file name' 'single'\''quote' 'double"quote'
dan% echo ${(qqq)a}
"file name" "single'quote" "double\"quote"
dan% print -l -- ${(qq)a}
'file name'
'single'''quote'
'double"quote'
dan% print -rl -- ${(qq)a}
'file name'
'single'\''quote'
'double"quote'
--
Dan Nelson
dnelson@xxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author