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

Re: Read file with escaped newlines into array



On Nov 19,  6:34pm, Sebastian Gniazdowski wrote:
}
} fc -W stores history to a given file. It escapes newlines with \. How
} to read such file into array and have "\^M" lines put back together
} into single array entries?

The best way is probably to use the history mechanism to read it:

    () { fc -ap -R the_given_file ; the_desired_array=( ${history} ) }

Although the docs don't yet say so, the special associative array
$history is not implemented as a hash table, so the entries are
guaranteed to be in a fixed order from most recent (largest history
number) to longest ago.  Which is the reverse of the way you'd read
them from the file, so you might want ${(Oa)the_desired_array} when
referencing.



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