Grep crashes inside a bash script, but works on the command line

Bash file:

#!/bin/bash grep -l -r "products" Products/ 

outputs a conclusion

 : No such file or directory 

When launched directly from the terminal prompt, grep -l -r "products" Products/ produces the desired result, which is a list of files containing the word.

I checked with echo $SHELL that the shell is really bash , so there should be no difference. What could be the reason? ( Products/ directory contains about 3500 files).

Powered by Ubuntu 12.04 LTS.

0
linux bash shell grep
source share
1 answer

Your script contains CR at the end of the grep line. Use dos2unix to remove it.

+5
source share

All Articles