linux shell-grep命令单词的模式匹配

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 ~]# 

猜你喜欢

转载自blog.csdn.net/z19861216/article/details/143021286