Advertisement
tolikpunkoff

askyn

May 10th, 2019
754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.34 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ask_y_n() #$1 - question
  4. {
  5.     echo -n "$1 [Y/N]: "
  6.     while [ 1 -eq 1 ];do
  7.     read -s -n1
  8.    
  9.     case "$REPLY" in
  10.         [yY])
  11.         echo
  12.         return 0
  13.         ;;
  14.         [nN])
  15.         echo
  16.         return 1
  17.         ;;
  18.     esac
  19.     done
  20. }
  21.  
  22.  
  23. ask_y_n "Run it?"
  24.  
  25. if [ "$?" -eq 0 ];then
  26.     echo "User ask YES!"
  27. else
  28.     echo "User ask NO :("
  29. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement