I am trying to do something in a bash script whenever a file in a directory I am iterating over contains a string using grep.  The problem comes in where a subset of the files in the directory contain spaces in the name.  Therefore, I have tried to replace the spaces with escaped spaces in place using sed:
if grep -c "main" ${source} | sed 's/ /\\ /g'; then
  # do something
fi
However, I still get the error:
grep: /Users/me/Desktop/theDir/nameWith: No such file or directory
grep: spaces.txt: No such file or directory
What am I doing wrong?
 
     
    