As @l0b0 pointed out, the problem is caused by a newline in git show
's output, right after "BODY" -- the read
command reads a single line, so it stops there. You can make it read the whole thing by changing its line delimiter character from newline to... nothing, with read -d ''
:
IFS='|' read -d '' -ra FIELDS <<< "$(git show --quiet --date=rfc --pretty=format:"%s|%b|%an, %ae|%H|%cd" $i)"
This sets ${FIELDS[0]}
to "SUBJECT", ${FIELDS[1]}
to "BODY\n", ${FIELDS[2]}
to "AUTHOR_NAME, AUTHOR_EMAIL", etc. One complication, however, is that it'll also treat the syntactic newline at the end of the output as part of the last field, i.e. ${FIELDS[4]}
will be set to "COMMIT_DATE\n".