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

Re: reading a file into an array. mapfile? (f)?



On Sep 19, 12:00pm, Peter Stephenson wrote:
} Subject: Re: reading a file into an array. mapfile? (f)?
}
} "Rocky Bernstein" wrote:
} > Further tests show that the behavior seems to be to drop blank lines
} > but put one at the end of the file.
} 
} Apologies, you're right; it seems you *do* need the @ flag, but my test
} was too simple to show it.
} 
} array=("${(f@)mapfile[foo.txt]}")
} 
} I'm not entirely sure why that is but I must be misremembering the (f)
} rules.

This is a fairly recent change (well, about a year ago):

     For historical reasons, the usual behaviour that empty array
     elements are retained inside double quotes is disabled for arrays
     generated by splitting; hence the following:

          line="one::three"
          print -l "${(s.:.)line}"

     produces two lines of output for one and three and elides the
     empty field.  To override this behaviour, supply the "(@)" flag as
     well, i.e.  "${(@s.:.)line}".



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