I'm trying to do something very simple that consists in insert a set of dates into an array. So I run a git command which wil return an one line result, from that result I'm getting the dates using awk. After I iterate over all dates and add them to the array. In the end, the array is still empty but if I print the array during the loop it seems to have data inside.
Why is the array empty after the loop?
git reflog --date=local <branch_name> |
awk '{ print $3 " " $4 " " $5 }' |
while read date; do a+=(`echo "$date"`); done; echo ${a[@]}
I understand that every command after a pipe is executed in a different subshell, but in this case I think it is not influencing the final result...