I have that bash script that shall read the output of git show
into an array.
First, I create a string with the following statement:
git show --quiet --date=rfc --pretty=format:"%s|%b|%an, %ae|%H|%cd" HEAD
Which gives me the pattern that I want:
SUBJECT|BODY|AUTHOR_NAME, AUTHOR_EMAIL|COMMIT_HASH|COMMIT_DATE
I can confirm that the resulting string does not contain a |
character on an unexpected place.
Next, I want to split up the string into it's fields as supposed in Split string into an array in Bash:
IFS='|' read -ra FIELDS <<< "$(git show --quiet --date=rfc --pretty=format:"%s|%b|%an, %ae|%H|%cd" $i)"
When I now look at FIELDS
, only the first two elements are filled, but the others are empty:
echo ${FIELDS[0]} # prints SUBJECT
echo ${FIELDS[1]} # prints BODY
echo ${FIELDS[2]} # prints nothing
echo ${FIELDS[3]} # prints nothing
echo ${FIELDS[4]} # prints nothing
What am I doing wrong? Why are the last three array elements empty?