Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux grep在bash脚本中失败,但在命令行中工作_Linux_Bash_Shell_Grep - Fatal编程技术网

Linux grep在bash脚本中失败,但在命令行中工作

Linux grep在bash脚本中失败,但在命令行中工作,linux,bash,shell,grep,Linux,Bash,Shell,Grep,bash文件: #!/bin/bash grep -l -r "products" Products/ 输出 : No such file or directory 当直接从终端提示符运行时,grep-l-r“products”products/会给出所需的输出,即包含单词的文件列表 我使用echo$SHELL检查SHELL是否确实是bash,因此应该没有区别。原因可能是什么?(Products/目录包含大约3500个文件) 在Ubuntu 12.04 LTS上运行。您的脚本在gre

bash文件:

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

: No such file or directory
当直接从终端提示符运行时,
grep-l-r“products”products/
会给出所需的输出,即包含单词的文件列表

我使用
echo$SHELL
检查SHELL是否确实是
bash
,因此应该没有区别。原因可能是什么?(
Products/
目录包含大约3500个文件)


在Ubuntu 12.04 LTS上运行。

您的脚本在grep行的末尾包含一个CR。使用
dos2unix
将其删除。

您的脚本在grep行的末尾包含一个CR。使用
dos2unix
将其删除。

pwd对此有何说明?尝试使用绝对路径eks:
/var/Products/
pwd对此有何说明?尝试使用绝对路径eks:
/var/Products/
谢谢!这确实是问题所在!谢谢这确实是问题所在!