#!/bin/bash
#A script to find a keyword. Name: findkey Version : 2.0 Author: devel
echo -n " ";pwd;date#空一格,显示当前路径和
while true;do#循环
echo "Input a directory or file : # will exit if press e|E !"
echo -n " ";read dir ; until [ $dir ] ;do read dir ;done#空出一格,从标准输入读取字符知道不为空
case $dir in
e|E) echo done ;exit 0
;;
*)
if [ -e $dir ];then#-e是检查是否存在
echo "Input keyword: # will exit if press e|E !
# Will reread a directory or file if you press r|R !"
echo -n " "; read "" ; until [ $key ] ;do read key ;done
case $key in
e|E) echo done ;exit 0 ;;
r|R) continue ;;#要求重新从标准输入读取路径
*) grep -R "$key" $dir|cat -n 2>/dev/null|less ;;#找出文件并排序
esac
else echo "The directory or file did not exist "
fi
;;
esac
done
阅读(1263) | 评论(0) | 转发(0) |