shell脚本实现菜单操作

  1. #!/bin/bash
  2. #written by wubo
  3. #blog:wbmtf.blog.51cto.com 
  4. while :
  5. do
  6. echo "请输入你要进行的操作:"
  7. select var in "edit file" "view ip" "delete file" "change directory" "exit" "view directory"
  8. do 
  9. break
  10. done
  11. case $var in
  12. "edit file")
  13. echo -n "please input edit file:"
  14. read file
  15. vim $file
  16. echo '编辑文件成功'
  17. ;;
  18. "view ip")
  19. echo -n "please input device name:"
  20. read file
  21. ifconfig $file
  22. echo '显示IP地址成功'
  23. ;;
  24. "delete file")
  25. echo -n "please input delete file:"
  26. read file
  27. rm -rf $file
  28. echo '成功删除文件'
  29. ;;
  30. "change directory")
  31. echo -n "please input change directory:"
  32. read file
  33. cd $file
  34. echo  "当前目录为:$(pwd)"
  35. ;;
  36. "view directory")
  37. echo -n "please input a directory:"
  38. read file
  39. ls $file
  40. echo "目录浏览成功"
  41. ;;
  42. "exit")
  43. break
  44. echo '退出成功'
  45. ;;
  46. *)
  47. break
  48. echo '退出成功'
  49. ;;
  50. esac
  51. done
  52.  

本文出自 “一起研究开源技术” 博客,谢绝转载!

你可能感兴趣的:(shell)