测试文件是否包含特定的文本内容sh脚本

来源:互联网 发布:java框架书籍 编辑:程序博客网 时间:2024/05/16 04:52

文件名:silent_grep.sh

文件内容:
if [ $# -ne 2 ];
then
echo "$0 match_text filename"
fi

match_text=$1
filename=$2

grep -q $match_text $filename
if [ $? -eq 0 ];
then
echo "The text exists in the file"
else
echo "Text does not exist in the file"
fi

 

文件执行方式:


[root@zhangshibo temp]# ./silent_grep.sh hack data.txt
The text exists in the file
[root@zhangshibo temp]# ./silent_grep.sh zhangshibo data.txt
Text does not exist in the file

 

原创粉丝点击