grep.sh

#!/bin/bash

success=0
word=22222
filename=/root/1.txt

grep -q "$word" "$filename"
#-q:静默查找,不输出到stdout上

if [ $? -eq $success ];then
  echo "$word found in $filename."
else
  echo "$word not found in $filename."
fi

验证:

[root@logstash ~]# sh grep.sh 
22222 found in /root/1.txt.
[root@logstash ~]# 

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐