Can I suggest a simple fix that doesn't involve changing behavior at all but probably improves the lives of the many users who hit this?
Just add an additional line to the error message for lines that look like this pattern:
sh: 107: command not found
Did you mean "AVAR=$(... | wc -l)"?