prompt.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/sh
  2. set -e
  3. # echo "Is this a good question (y/n)? "
  4. # old_stty_cfg=$(stty -g)
  5. # stty raw -echo; answer=$(head -c 1) ; stty "$old_stty_cfg"
  6. # if echo "$answer" | grep -iq "^y"; then
  7. # echo Yes
  8. # else
  9. # echo No
  10. # fi
  11. # echo "Is this a good question (y/n)? "
  12. # old_stty_cfg=$(stty -g)
  13. # stty raw -echo
  14. # answer=$( while ! head -c 1 | grep -i '[ny]' ;do true ;done )
  15. # stty "$old_stty_cfg"
  16. # if echo "$answer" | grep -iq "^y" ;then
  17. # echo Yes
  18. # else
  19. # echo No
  20. # fi
  21. # [[ -t 0 ]] &&
  22. # read -n 1 -p $'\e[1;32m
  23. # Do xxxx? (Y/n)\e[0m ' do_xxxx
  24. # if [[ $do_xxxx =~ ^(y|Y|)$ ]]
  25. # then
  26. # xxxx
  27. # fi
  28. # while true; do
  29. # read -rp "Ask question" yn
  30. # case $yn in
  31. # [Yn]* ) okay; break;;
  32. # [Nn]* ) exit;;
  33. # * ) echo "Yes or No.";;
  34. # esac
  35. # done
  36. echo Would you like to proceed? "(Y or N)"
  37. #read x
  38. ##now check if $x is "y"
  39. #if [ "$x" = "y" ]; then
  40. # echo "yup"
  41. #else
  42. # echo "nope"
  43. #fi
  44. # read -r input
  45. # case $input in
  46. # "Y") echo "yay"
  47. # ;;
  48. # "N") echo "nay"
  49. # ;;
  50. # esac
  51. # exit
  52. echo "Prompting for yes or no"
  53. read -r yesno < /dev/tty
  54. if [ "$yesno" = "xy" ]; then
  55. echo "yup"
  56. else
  57. echo "nay"
  58. fi