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

The Z Shell Manual, zsh/mapfile documentation correction


While working on a zsh script, I researched using module zsh/mapfile to
read a file into an array for further processing.  Trying the example from *The
Z Shell Manual*(Section 22.15) I found that it didn't work as stated.  It
failed to read in blank lines.  I had also noticed an extra element in the

Example:  array=("${(f)mapfile[*filename*]}")


egrep -v '^$' filename | wc -l  yielded n lines
print ${#array} yielded n+1 elements

Not that I needed the blank lines, in this case, but it did not read them
into the array.  After some web searching I found that this was discussed
on zsh-users in the 2008 thread *reading a file into an array. mapfile? (f)?
*.  URL:  http://www.zsh.org/mla/users/2008/msg00849.html.  The fix was
actually stated in URL: http://www.zsh.org/mla/users/2008/msg00874.html.

Correction:  array=("${(f@)mapfile[*filename*]}")

The discussion also stated the fact that an extra element(blank) is added
to the end of the array.  It would be nice to have a statement in *The Z
Shell Manual* that the array will contain an additional element.  I'm not
sure I agree that this should be the result, but I'll leave that to others
more knowledgeable about the subject.

Versions of the manual I checked are:
  4.3.17  -- This is also the version of zsh I'm using(OS: Debian Wheezy).



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