#!/bin/bash
######## My homework for Network Operating System#########
######## To find files that contains the entered string###########
#######################################################
if test $# -ne 2####判断参数是否合法
then
echo "Please enter the Directory that you want to search:/c"
read dir#####读入用户输入目录
echo "Please enter the word you want to find:/c"
read word###读入用户输入字符串
dir=${dir}*
if grep -n $word $dir
then
echo "The result is listed above!"
exit 0
else
echo "Sorry,The word was not found."
exit -1
fi
else
dir=$1
word=$2
dir=${dir}*
if grep -n $word $dir#这里我用grep带n参数来过滤出来文件。
then
echo "The result is listed above!"
else
echo "Sorry,The word was not found."
fi
fi
exit 0
######## My homework for Network Operating System#########
######## To find files that contains the entered string###########
#######################################################
if test $# -ne 2####判断参数是否合法
then
echo "Please enter the Directory that you want to search:/c"
read dir#####读入用户输入目录
echo "Please enter the word you want to find:/c"
read word###读入用户输入字符串
dir=${dir}*
if grep -n $word $dir
then
echo "The result is listed above!"
exit 0
else
echo "Sorry,The word was not found."
exit -1
fi
else
dir=$1
word=$2
dir=${dir}*
if grep -n $word $dir#这里我用grep带n参数来过滤出来文件。
then
echo "The result is listed above!"
else
echo "Sorry,The word was not found."
fi
fi
exit 0