专注各种脚本编程
Baidu
加入收藏夹
本站内容有下面分类知识,欢迎您的到来^_^
shell相关:指令篇 基础篇 脚本欣赏 编程实例 shell问问 shell视频教程 技巧篇 水平测试 E文资料 vi编辑器 高级Bash脚本编程指南
其他:mysql perl c语言 oracle
当前位置:| 主页>shell脚本欣赏>

找出文件中某个KEY的shell脚本(版本2)

百度收藏 QQ搜藏

非常好用,我很喜欢它!!

代码:
#!/bin/bash
#A bash 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 "key" ; 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

上一篇:一个利用suspend控制终端的shell脚本 下一篇:一个实现自动分区的shell脚本

power by soyo123 2007-2008