文件名: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