This works fine for str1 (aka I can see "done" as output)
However, if I use str2, after assigning empty string for str2. The script stops there. And I do not see any output at all.
The exit code of the assignment is the exit code of the last command of the pipe line which is grep. Since grep didn't find any matching data, it exited with 1. The shell script exited since you have set -e at the beginning.