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

Re: Fwd: more splitting travails



On Fri, Jan 12, 2024 at 1:57 PM Mark J. Reed <markjreed@xxxxxxxxx> wrote:
>
> On Fri, Jan 12, 2024 at 15:52 Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
>>
>> ** Except that $(...) trims off TRAILING newlines>
>
>I didn't realize *multiple* new lines would get chomped, either; I thought it was just the last one.

Yeah, oddly, there's no straightforward way to get an unaltered file
into a shell variable.  Even
  read -rd '' < file
trims off trailing newlines.  The only somewhat-obvious way is to use
  zmodload zsh/mapfile
  var=$mapfile[file]
but up until a recent dev version, on platforms that don't implement
memmap that just sneakily reverts to $(<file).

I'm expecting Roman or someone to point out a different trick I've forgotten.




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