我试图使用if语句与grep
为了检查某个文件中是否存在字符串。现在,grep
声明工作本身,但是当我运行它作为if
语句的一部分输出为:太多的论据如果声明Bash
line 6: [: too many arguments
我的代码:
#!/bin/bash
if [ $(grep -c "OutOfMemory" /my/path/to/domains/*/*/subdomains/*/logs/*.*) -ne 0 ];
then
echo "String found"
else
echo "String not found"
fi
如果使用更短的路径尝试,但它没没有帮助。
任何建议都会有所帮助。
谢谢
使用'find'搜索的文件,然后找到的exec会帮助你给grep。然后将结果存储在某个变量中并使用它。没有回答。有很多例子 – abasu 2013-04-24 16:29:28