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

Re: string to array space problem in filenames



On Fri, 28 Aug 2015 12:43:34 -0700
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> Your first problem here is trying to maintain .mydirstack all as one
> line (echo -n) with spaces between the fields.  You would be much
> better served by writing one file name per line and then splitting
> the file on newlines when reading it back.

In fact, the cdr suite (chpwd_recent_filehandler) does this as essentially

print -rl -- ${(qqqq)array_of_dirs}

The four q's means use $' style quoting for this.  The advantage here is
if a string contains a newline (bad karma for a directory, but let's
think in general) it gets written as $'...\n...' --- so it's always safe
to read back a single line at a time and strip the quotes with ${(Q)...}.

For efficiency, in fact, it reads the file into an array of lines using
${(f)"$(<$file)"} and takes the lines out of that array.

pws



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