echo "string" | grep -q in && echo yes
echo "string" | grep -q out && echo yes
在您的情况下:
searchdir="/usr/lib/cgi-bin/ParkingSoft/api/v3/LaneApi/ETC/MywebSocket "
if [ ! -d "$searchdir" ]; then
echo "Check searchdir. Is 'ETC' really in uppercase and is `Mywebsocket ` including a space?"
else
if grep -rwq '34161FA8203289722240CD40' "${searchdir}/*.txt; then
echo "String found in one of the files."
fi
fi
2条答案
按热度按时间bfrts1fy1#
试试这个:
上面的命令返回包含
target_string
的所有文件的名称。要了解
-rwl
,请查看answer,但是awk -F "/" '{print $NF}'
只是拆分grep
输出并返回最后一部分。(文件名在您的情况下)7y4bm7vi2#
如果找不到匹配项,
-q
选项将返回(退出代码)1。在您的情况下: