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