当前位置: 技术问答>linux和unix
傻瓜grep脚本
来源: 互联网 发布时间:2017-05-05
本文导语: 本帖最后由 songjinshi 于 2013-12-23 15:29:17 编辑 #!/bin/sh if [ "$1" = "" ] then echo -e "The first parameter can not be empty.nPlease check the first parameter from your input." #exit 1 elif [ "$2" = "" ] then echo -e "The second parameter can not be em...
#!/bin/sh
if [ "$1" = "" ]
then
echo -e "The first parameter can not be empty.nPlease check the first parameter from your input."
#exit 1
elif [ "$2" = "" ]
then
echo -e "The second parameter can not be empty.nPlease check the second parameter from your input."
#exit 2
elif [ "$3" = "" ]
then
echo -e "The third parameter can not be empty.nPlease check the third parameter from your input."
#exit 3
elif [ "$4" = "" ]
then
echo -e "The fourth parameter is null.nDefault output to current findReslut.txt file."
filelist=$(find $2 -name $3)
if [ "$filelist" != "" ]
then
grep -n $1 -r $filelist > findResult.txt
#exit 4
fi
else
filelist=$(find $2 -name $3)
if [ "$filelist" != "" ]
then
grep -n $1 -r $(find $2 -name $3) > $4
fi
fi
|
不要所有的代码都定格写
#!/bin/sh
if [ "$1" = "" ]
then
echo -e "The first parameter can not be empty.nPlease check the first parameter from your input."
#exit 1
elif [ "$2" = "" ]
then
echo -e "The second parameter can not be empty.nPlease check the second parameter from your input."
#exit 2
elif [ "$3" = "" ]
then
echo -e "The third parameter can not be empty.nPlease check the third parameter from your input."
#exit 3
elif [ "$4" = "" ]
then
echo -e "The fourth parameter is null.nDefault output to current findReslut.txt file."
filelist=$(find $2 -name $3)
if [ "$filelist" != "" ]
then
grep -n $1 -r $filelist > findResult.txt
#exit 4
fi
else
filelist=$(find $2 -name $3)
if [ "$filelist" != "" ]
then
grep -n $1 -r $(find $2 -name $3) > $4
fi
fi