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

Re: string to array space problem in filenames



On Thu, Sep 3, 2015 at 7:25 AM, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Sep 2,  8:37pm, Ray Andrews wrote:
> }
> } I've got it all more or less working except I can't figure out how to
> } write the array--with newlines now, not with spaces--back to the file.
>
> You mean like:
>
>     print -l "${array[@]}" > file
>
> ?
>
> (Or Kurtis's answer if you need the newlines in the string *before* it
> goes to the file.)

For print you also want -r -, and for echo you want -E -, so
print -rl - "${array[@]}" > file
or
echo -E - ${(F)array} > file

the -r/-E makes the builtins not expand \-sequences, and the -
terminates the option list or you'd get
% array=(-foo bar)
% print -l ${(F)array}
oo
bar

although if the paths are absolute, this is quite unlikely to be an
issue, but it never hurts to have the - there.

-- 
Mikael Magnusson



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