On Mon, Jan 13, 2025 at 04:11:46 -0500, Lawrence Velázquez wrote: > What exactly is all of this supposed to demonstrate? mapfile has > the same terminator-not-separator behavior everyone is kvetching > about: > > $ printf 'a:b:c:' | { mapfile -td:; declare -p MAPFILE; } > declare -a MAPFILE=([0]="a" [1]="b" [2]="c") > > Reading a line and splitting it into an array like this is what > read -a is for.
Yeah. It does what you expect if and only if the delimiter is the default newline character (or a NUL). If it's anything else, you run into the same issue this thread has been discussing for days. In a previous message, I mentioned that field terminators didn't seem like a common choice in any kind of data files. I forgot that text files sort of fit this mold: every line, including the final one, is supposed to be terminated by a newline character. Unfortunately, you can't actually use the shell's word splitting to separate a text file into a list of lines, *except* by using mapfile. Any other choice runs into either the "leading/trailing IFS whitespace gets trimmed" feature, or the "command substitution strips trailing newlines" feature.