Advertisement
Guest User

Untitled

a guest
Apr 18th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Asks the user a yes or no question, returning the boolean result
  4. # $1: Message message to print
  5. # $2: Default answer (defaults to "no" (1))
  6. std_askyesno() {
  7. local CONF="y/N"
  8. if [[ $2 == 0 ]]; then local CONF="Y/n"; fi
  9. local reply="n"
  10. read -p "$1 $CONF " -n 1 -r reply
  11. if [[ "$reply" ]]; then echo; fi
  12. if [[ $reply =~ ^[Yy]$ ]]; then
  13. return 0
  14. elif [[ $reply =~ ^[Nn]$ ]]; then
  15. return 1
  16. elif [[ $2 ]]; then
  17. return $2
  18. else
  19. return 1
  20. fi
  21. }
  22.  
  23. if std_askyesno "Are you really sure?"; then
  24. echo "User answered yes"
  25. else
  26. echo "User answered no"
  27. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement