• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

菜鸟学习SHELL第一课---地址本的脚本

发布: 2007-7-04 12:06 | 作者: admin | 来源:  网友评论 | 查看: 9次 | 进入软件测试论坛讨论

领测软件测试网
  一个地址本的脚本,可供学shell的人参考
  -------------addr.sh------------
  #!/bin/bash
  clear
  . /etc/rc.d/init.d/functions
  
  arg_count=$#
  if [ $arg_count -eq 0 ]; then
  FILENAME=/tmp/addr
  elif [ $arg_count -eq 1 ]; then
  FILENAME=$1
  else
  echo -e $"07Usage:
  $0 filename"
  exit 1
  fi
  
  add(){
  echo
  echo -e " N A M E :c"
  read name
  echo
  echo -e " P O S I T I O N :c"
  read position
  echo
  echo -e " T E L E P H O N E :c"
  read telephone
  echo
  echo -e " E _ M A L E :c"
  read email
  echo -e "$name $position $telephone $email" >> $FILENAME
  echo
  echo -e " Do you wish to proceed?[y/n]:c"
  read proceed
  echo
  case $proceed in
  y|Y|yes|Yes|YES)
  add
  ;;
  n|N|No|NO)
  clear
  main
  ;;
  *)
  echo -e " Please input y|Y|yes|Yes|YES or n|N|No|NO"
  exit 1
  esac
  }
  proceed(){
  case $1 in
  y|Y|yes|Yes|YES)
  $2 $3 $4 $FILENAME > $FILENAME.tmp
  mv $FILENAME.tmp $FILENAME
  echo
  echo -e " Line Deleted!"
  ;;
  n|N|No|NO)
  echo
  ;;
  *)
  echo -e " Please input y|Y|yes|Yes|YES or n|N|No|NO"
  echo
  esac
  
  }
  del(){
  clear
  echo
  echo -e " ------------------------------------"
  echo -e " | 1. Del record by Line |"
  echo -e " | 2. Del record by Name |"
  echo -e " | 3. Del record by Tel |"
  echo -e " | 4. Show all record |"
  echo -e " | 5. Exit |"
  echo -e " ------------------------------------"
  echo
  echo -e " Your selection:c"
  read selection
  echo
  case $selection in
  1)
  echo -e " Input Start_Line_Number:c"
  read line1
  echo
  echo -e " Input End_Line_Number:c"
  read line2
  echo
  echo -e " Line$line1 to Line$line2 are:"
  echo
  echo -e " 姓 名 职 位 电 话 电子邮件"
  echo
  sed -n '$line1','$line2'p' $FILENAME |cat -n
  echo
  echo -e " Delete really?[y/n]:c"
  read proceed
  proceed $proceed sed '$line1','$line2'd'
  ;;
  2)
  echo -e " Input Name:c"
  read name
  echo
  echo -e " record include $name are:"
  echo
  echo -e " 姓 名 职 位 电 话 电子邮件"
  echo
  grep -w ^$name $FILENAME |cat -n
  echo
  echo -e " Delete really?[y/n]:c"
  read proceed
  proceed $proceed grep -vw ^$name
  ;;
  3)
  echo -e " Input Telephone:c"
  read telephone
  echo
  echo -e " record include $telephone are:"
  echo
  echo -e " 姓 名 职 位 电 话 电子邮件"
  echo
  grep -w $telephone $FILENAME |cat -n
  echo
  echo -e " Delete really?[y/n]:c"
  read proceed
  proceed $proceed grep -vw $telephone
  ;;
  4)
  echo
  show
  ;;
  5)
  echo
  main
  ;;
  *)
  clear
  del
  esac
  
  echo
  echo -e " Do you wish to proceed?[y/n]:c"
  read proceed
  echo
  case $proceed in
  y|Y|yes|Yes|YES)
  clear
  del
  ;;
  n|N|No|NO)
  echo
  main
  ;;
  *)
  echo -e " Please input y|Y|yes|Yes|YES or n|N|No|NO"
  echo
  exit 1
  esac
  }
  
  
  show(){
  echo
  echo -e " 姓 名 职 位 电 话 电子邮件"
  echo
  cat -n $FILENAME
  echo
  echo -e " Do you wish to proceed?[y/n]:c"
  read proceed
  echo
  case $proceed in
  y|Y|yes|Yes|YES)
  main
  ;;
  n|N|No|NO)
  echo
  exit 1
  ;;
  *)
  echo -e " Please input y|Y|yes|Yes|YES or n|N|No|NO"
  echo
  exit 1
  esac
  }
  
  main(){
  clear
  echo
  echo -e " --------------------------------"
  echo -e " | 1. Add record |"
  echo -e " | 2. Del record |"
  echo -e " | 3. Show record |"
  echo -e " | 4. Exit |"
  echo -e " --------------------------------"
  echo
  echo -e " Your selection:c"
  read selection
  echo
  
  case $selection in
  1)
  add
  ;;
  2)
  del
  ;;
  3)
  show
  ;;
  4)
  exit 1
  ;;
  *)
  main
  esac
  }
  main  (chinaunix)
  

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网