while IFS= read -rd '' file; #What '' is doing?
do
Thie while loop will read each line returned by the command (exec grep -ZFlR "$str" "$dir"). You see it is being used to 'feed' data to the loop at the end: done < <(exec grep -ZFlR "$str" "$dir") Beginning with the while loop you see IFS=. That unsets the Internal Field Separator (IFS) in bash which determines what separates a given string of words into separate fields. (the defaults IFS=$'space tab newline' which you see written like IFS=$' \t\n')
The while loop continues with read -rd '' file; As discussed the input is coming from the exec grep.. expression at the end, and read -rd '' file is reading that input up to the first '' which is specified by -d to be the delimeter to use with this read. read then stores the matching input in the variable file. So the '' is just serving as the delimeter for read as specified by the -d option to read. (that explains why IFS was unset at the beginning, they wanted to use the specific '' delimiter in this case.
base=${file##*/} #Please explain
All this says is use parameter expansion to delete eveything in string beginning from the left up to (and including) the last / character. (that is what ## means). It is stipping the path information from the filename leaving only the filename in base.
dir=${file%/*} #Please explain
Here this is similar parameter expansion, but here, we start from the right (%) and delete all characters up to, and including, the first / character in file leaving only the path information in dir. (makes sense)
done < <(exec grep -ZFlR "$str" "$dir")
Just feeds the loop as we discussed above.