grep "string" myfile
if [ $? -eq 0 ]
then
echo 字符串string存在与文件myfile中
else
echo 字符串string不存在与文件myfile中
fi
说明:
1.$? 代表上一条命令的返回值
grep 找到 字符串会返回0
没找到会返回1
grep "string" myfile
if [ $? -eq 0 ]
then
echo 字符串string存在与文件myfile中
else
echo 字符串string不存在与文件myfile中
fi
说明:
1.$? 代表上一条命令的返回值
grep 找到 字符串会返回0
没找到会返回1