grep_match.sh
#!/bin/bash
#Description:word matches
success=0
word=afa
filename=/root/2.txt
grep -q "$word" "$filename"
if [ $? -eq $success ];then
echo "$word found in $filename"
else
echo "$word not found in $filename"
fi
验证:
[root@logstash ~]# sh grep_match.sh
afa found in /root/2.txt
[root@logstash ~]#