【发布时间】:2019-02-10 22:37:07
【问题描述】:
我想检查文件是否存在,然后检查文件中的子字符串
if [ -f /etc/abc.conf ]; then
if [ grep 'abc.conf' -e 'host.com' ]
test = 'PASS'
else
test = 'FAIL'
fi
else
echo "File doesnot exist"
fi
echo $test
如果有更好的方法,请告诉我
【问题讨论】:
-
你问是因为这个 sn-p 不起作用吗?尝试shellcheck 找出错误和缺失的语法。
-
有一个更好的方法,因为你现在拥有的东西根本就坏了。
-
@BenjaminW。怎么是复制品?答案中没有一个关于不存在文件的词:-(