I split the functionality into two files.
The first script calls inotifywait and tees the result to a file called "test"
DIR="c:/tmp"
(inotifywait -mr --timefmt '%m/%d/%y %H:%M:%S' \
--format '%T;%f;%e;%w' $DIR) |& tee test
The second script does the while do loop on the output of tail -f test. "test" is the file name.
tail -f test |
while read line
do
#form the line string with semi colons between fields
lineString=$(echo $line | awk -F'[;]' 'echo $1;$2;$3;$4')
#store the elements in the array
IFS=';' read -a inotifyElements <<< "${lineString}"
datetime=${inotifyElements[0]}
filename=${inotifyElements[1]}
event=${inotifyElements[2]}
pathname=${inotifyElements[3]}
echo $datetime " " $filename " " $event " " $pathname
done