海是我向往的地方,吸纳和咆哮是他的魅力!!!
shell脚本 (实例)
上一篇 /
下一篇 2008-09-18 14:19:47
从指定目录开始查找文件中的内容
#!/bin/sh
# user: /usr/bin/mygrep strings pat
if [ $# -lt 2 ] ; then
echo "Usage: mygrep word dirctory/files"
exit 1
fi
if test -d $2; then
ls -l $i | grep ">" >/tmp/name.temp
#if file not link, go check
if [ "$?" -ne 0 ]
then
cd $2
for i in *
do
if test -d $i;then
$0 $1 $i
else
if test -r $i;then
ls -l $i | grep ">" >/tmp/name.temp
#if file not link, go check
if [ "$?" -ne 0 ]
then
grep $1 $i > /tmp/grep.temp
if test -s /tmp/grep.temp;then
echo `pwd`/$i:
cat /tmp/grep.temp
echo
else
rm /tmp/name.temp
fi
fi
fi
fi
done
fi
cd ..
else
grep $1 $2 > /tmp/grep.temp
if test -s /tmp/grep.temp;then
echo 'pwd'/$2:
cat /tmp/grep.temp
echo
fi
fi
if test -f /tmp/grep.temp
then
rm /tmp/grep.temp
fi
exit 0
收藏
举报
TAG: