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

Re: Printing arrays for use with $()



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