请教:如何在每次暂停时增加“Y” “N”选择是否执行本段命令?“y"执行本段,”n"跳到下一段?
Tofloor
poster avatar
Coollove
deepin
2012-04-21 18:31
Author
代碼:
  1. #! /bin/bash
  2. function pause(){
  3.         read -n 1 -p "$*" INP
  4.         if [[ $INP != '' ]] ; then
  5.                 echo -ne '\b \n'
  6.         fi
  7. }
  8. echo “请设置root密码”
  9. pause 'Press [Enter] key to continue...'
  10. sudo passwd root
  11. echo “同步Reaver设置”
  12. pause 'Press [Enter] key to continue...'
  13. Folder=~/.config/reaver
  14. if [ -d "$Folder" ]; then
  15. sudo rm -fr /usr/local/etc/reaver
  16. sudo ln -fsT ~/.config/reaver /usr/local/etc/reaver
  17. else
  18. mkdir -p "$Folder"
  19. cp -at /usr/local/etc/reaver ~/.config/reaver
  20. fi
  21. echo “设置本地源”
  22. pause 'Press [Enter] key to continue...'
  23. Folder="/media/iData/Backup/Ubuntu/Packages"
  24. if [ -d "$Folder" ]; then
  25. sudo rm -fr /var/cache/apt/archives
  26. sudo ln -fsT "/media/iData/Backup/Ubuntu/Packages" "/var/cache/apt/archives"
  27. else
  28. mkdir -p "$Folder"
  29. fi
  30. #sources.list
  31. sudo add-apt-repository ppa:kernel-ppa/pre-proposed
  32. sudo add-apt-repository ppa:ubuntu-wine/ppa
  33. sudo add-apt-repository ppa:tualatrix/ppa
  34. sudo add-apt-repository ppa:ubun-tor/ppa
  35. sudo add-apt-repository ppa:deluge-team/ppa
  36. sudo add-apt-repository ppa:hydr0g3n/ppa
  37. sudo add-apt-repository ppa:thopiekar/oneiric-dev
  38. sudo add-apt-repository ppa:jason-scheunemann/ppa
  39. sudo add-apt-repository ppa:team-xbmc/unstable
  40. sudo add-apt-repository ppa:jonoomph/openshot-edge
  41. echo “更新系统”
  42. pause 'Press [Enter] key to continue...'
  43. sudo apt-get update
  44. sudo apt-get dist-upgrade
  45. echo “任意键退出”
  46. pause 'Press any key to continue...'
Copy the Code


请教:如何在每次暂停时增加“Y” “N”选择是否执行本段命令?“y"执行本段,”n"跳到下一段?
Reply Favorite View the author
All Replies
tuhaihe
deepin
2012-04-26 18:09
#1
是不是来个条件判断?
Reply View the author
cnchanghai
deepin
2012-05-31 02:07
#2
我也不懂,但是我认为你可以做个输入
像这个

echo 请选择
a=get
if a==‘Y’
。。。
else
。。。
Reply View the author